我希望我的用户访问它的个人资料编辑页面的网址:/profile/slug/edit,其中段塞的意思是$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>发布于 2017-04-16 10:56:26
这是我怎么做的..。
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,我们从路由文件中知道它缺少段塞值,所以我们提供它作为第二个参数(如果有更多的缺失值,第二个参数应该是一个数组)。
这需要一些实践和时间,但是尝试不同的方法来看看是什么使您的代码更加可读性。对于计算机来说,行数没有多大关系,写代码,这样你就可以轻松地阅读和理解它,如果你想在一到两年后改变它。
发布于 2017-04-16 11:21:53
您可以使用以下代码线
<a href="{{ route('profile.edit', ['slug' => Auth::user()->slug]) }}"> Edit your profile</a>您的路线定义似乎很好。
另外,如果要添加一些get params,可以直接在作为第二个参数传递的数组中添加。
<a href="{{ route('profile.edit', ['slug' => Auth::user()->slug, 'otherparam' => 'value']) }}"> Edit your profile</a>希望这能有所帮助。:)
https://stackoverflow.com/questions/43426942
复制相似问题