将带有资源路由的参数传递给控制器 Laravel



我有这样的资源路由

Route::resource('users','UsersController');

我想将数组和变量传递给索引页面或创建页面所以我需要它像这样

Route::resource('users','UsersController')-> with array to use it in the functions; // with array passed 

并像这样在我的控制器中使用它

public function index()
{
   return $my_array_passed_from_route;
    if(Gate::allows('users.view'))
    {
        $users = User::withTrashed()->paginate(100);
        return view('users.index',compact('users'));
    }
    else
        return Helper::not_auth();
}

多谢

你应该尝试下面的代码

Route::get('users/{id}', [
'as' => 'users.show',
'uses' => 'UsersController@show'
]);
Route::resource('user', 'UsersController', ['except' => 'show']);

https://laracasts.com/discuss/channels/laravel/pass-parameter-to-resource-controller

最新更新