php – 如何将href中的值传递给laravel控制器?

前端之家收集整理的这篇文章主要介绍了php – 如何将href中的值传递给laravel控制器?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的视图文件中的代码段.

@foreach($infolist as $info)
 <a href="">{{$info->prisw}} / {{$info->secsw}}</a>
@endforeach

这是我在路径文件中定义的路线

Route::get('switchinfo','SwitchinfoController');

我想将href标记内的两个值传递给上面的路径并在控制器中检索它们.有人可以提供代码来做这件事吗?

解决方法

由于您尝试将两个参数传递给控制器​​,

您的控制器可能如下所示:

<?PHP namespace App\Http\Controllers;

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

猜你在找的Laravel相关文章