用户路由 Laravel 5.4
User routing Laravel 5.4
我希望我的用户通过 URL: /profile/slug/edit
访问其个人资料编辑页面,其中 slug 表示 $user->slug
。
我的 web.php
包含:
Route::group(['middleware' => 'auth'], function () {
Route::get('/profile/{slug}', [
'uses' => 'ProfilesController@index',
'as' => 'profile'
]);
Route::get('/profile/{slug}/edit', [
'uses' => 'ProfilesController@edit',
'as' => 'profile.edit'
]);
如何从视图中调用ProfilesController@edit
,如何正确传递参数?尝试过:
<a href="{{route('profile', ['slug'=> Auth::user()->slug],'edit')}}">
Edit your profile</a>
这是我的做法..
Route::group(['middleware' => 'auth'], function () {
Route::get('/profile/{slug}', 'ProfilesController@index')->name('profile');
Route::get('/profile/{slug}/edit', 'ProfilesController@edit')->name('profile.edit');
});
然后在你看来,你可以使用..
<a href="{{ route('profile.edit', Auth::user()->slug) }}">Edit your profile</a>
如您所见,首先我们必须给 route()
我们感兴趣的路线名称,在您的情况下 profile.edit
是目标路线,我们从路线中知道文件表明它缺少 slug 值,因此我们将 slug 值作为第二个参数提供给它(如果有更多缺失值,第二个参数应该是一个数组)。
这需要一些练习和时间,但尝试不同的方法可以让您的代码更具可读性。行数对计算机来说并不重要,如果你想在一两年后更改某些内容,请编写代码以便你可以轻松阅读和理解它。
您可以使用以下代码行
<a href="{{ route('profile.edit', ['slug' => Auth::user()->slug]) }}"> Edit your profile</a>
您的路由定义似乎没问题。
此外,如果你想添加一些get参数,你可以直接在作为第二个参数传递的数组中添加
<a href="{{ route('profile.edit', ['slug' => Auth::user()->slug, 'otherparam' => 'value']) }}"> Edit your profile</a>
希望这对您有所帮助。 :)
我希望我的用户通过 URL: /profile/slug/edit
访问其个人资料编辑页面,其中 slug 表示 $user->slug
。
我的 web.php
包含:
Route::group(['middleware' => 'auth'], function () {
Route::get('/profile/{slug}', [
'uses' => 'ProfilesController@index',
'as' => 'profile'
]);
Route::get('/profile/{slug}/edit', [
'uses' => 'ProfilesController@edit',
'as' => 'profile.edit'
]);
如何从视图中调用ProfilesController@edit
,如何正确传递参数?尝试过:
<a href="{{route('profile', ['slug'=> Auth::user()->slug],'edit')}}">
Edit your profile</a>
这是我的做法..
Route::group(['middleware' => 'auth'], function () {
Route::get('/profile/{slug}', 'ProfilesController@index')->name('profile');
Route::get('/profile/{slug}/edit', 'ProfilesController@edit')->name('profile.edit');
});
然后在你看来,你可以使用..
<a href="{{ route('profile.edit', Auth::user()->slug) }}">Edit your profile</a>
如您所见,首先我们必须给 route()
我们感兴趣的路线名称,在您的情况下 profile.edit
是目标路线,我们从路线中知道文件表明它缺少 slug 值,因此我们将 slug 值作为第二个参数提供给它(如果有更多缺失值,第二个参数应该是一个数组)。
这需要一些练习和时间,但尝试不同的方法可以让您的代码更具可读性。行数对计算机来说并不重要,如果你想在一两年后更改某些内容,请编写代码以便你可以轻松阅读和理解它。
您可以使用以下代码行
<a href="{{ route('profile.edit', ['slug' => Auth::user()->slug]) }}"> Edit your profile</a>
您的路由定义似乎没问题。
此外,如果你想添加一些get参数,你可以直接在作为第二个参数传递的数组中添加
<a href="{{ route('profile.edit', ['slug' => Auth::user()->slug, 'otherparam' => 'value']) }}"> Edit your profile</a>
希望这对您有所帮助。 :)