我有这样的资源路线
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();
}
非常感谢
答案 0 :(得分:2)
你必须尝试这个
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