php – 如何将href中的值传递给laravel控制器?
发布时间:2020-12-14 19:35:52 所属栏目:大数据 来源:网络整理
导读:这是我的视图文件中的代码段. @foreach($infolist as $info) a href=""{{$info-prisw}} / {{$info-secsw}}/a@endforeach 这是我在路径文件中定义的路线 Route::get('switchinfo','SwitchinfoController'); 我想将href标记内的两个值传递给上面的路径并在控制
这是我的视图文件中的代码段.
@foreach($infolist as $info) <a href="">{{$info->prisw}} / {{$info->secsw}}</a> @endforeach 这是我在路径文件中定义的路线 Route::get('switchinfo','SwitchinfoController'); 我想将href标记内的两个值传递给上面的路径并在控制器中检索它们.有人可以提供代码来做这件事吗? 解决方法
由于您尝试将两个参数传递给控制器??,
您的控制器可能如下所示: <?php namespace AppHttpControllers; class SwitchinfoController extends Controller{ public function switchInfo($prisw,$secsw){ //do stuffs here with $prisw and $secsw } } 你的路由器看起来像这样 $router->get('/switchinfo/{prisw}/{secsw}',[ 'uses' => 'SwitchinfoController@switchInfo','as' => 'switch' ]); 然后在你的刀锋中 @foreach($infolist as $info) <a href="{!! route('switch',['prisw'=>$info->prisw,'secsw'=>$info->secsw]) !!}">Link</a> @endforeach (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |