簡體   English   中英

如何解決laravel 5.3中未定義的路由?

[英]How to solve route not defined in laravel 5.3?

我的控制器代碼是這樣的:

public function store(CreateUserRequest $request)
{
    $input = $request->all();

    $user = $this->userRepository->create($input);

    Flash::success('User saved successfully.');

    return redirect(route('user.index.'.$input['year']));
}

存在這樣的錯誤:

UrlGenerator.php第314行中的InvalidArgumentException:路由[users.index.2016]未定義。

錯誤時,URL如下所示: http://localhost/mysystem/public/users

我的routes \\ web.php是這樣的:

Route::get('users/index/{year}', 'UserController@index')->name('users.index.year');

Route::get('users/create/{year}', 'UserController@create')->name('users.create.year');

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

我希望網址看起來像這樣: http://localhost/mysystem/public/users/index/2016

有沒有人可以幫助我?

您應該按以下方式調用route()函數:

route('users.index.year', ['year' => $year])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM