【发布时间】:2020-12-11 23:05:04
【问题描述】:
在 Laravel 中,我需要编辑由 Auth/RegisterController 创建的用户,但使用我创建的控制器,例如 ProfileController。但是当我尝试通过 a:href 按钮访问时,显示 404 错误。
代码:
web.php
Route::group(['middleware' => ['auth']], function(){
Route::resource('profile', 'ProfileController')->except(['edit']);
Route::get('profile/{profile}/edit', ['as' => 'profile.edit', 'uses' => 'ProfileController@edit']);
});
Auth::routes();
app.blade.php
<a href="{{route('profile.edit',['profile'=>auth()->user()->id])}}" class="btn btn-primary">
{{auth()->user()->email}}
</a>
配置文件控制器
public function edit($profile)
{
$user = \App\User::findOrFail($profile);
return view('profile.edit', compact('user'));
}
列出路线
| | POST | profile | profile.store | App\Http\Controllers\ProfileController@store | web,auth,guest |
| | GET|HEAD | profile | profile.index | App\Http\Controllers\ProfileController@index | web,auth,guest |
| | GET|HEAD | profile/create | profile.create | App\Http\Controllers\ProfileController@create | web,auth,guest |
| | DELETE | profile/{profile} | profile.destroy | App\Http\Controllers\ProfileController@destroy | web,auth,guest |
| | PUT|PATCH | profile/{profile} | profile.update | App\Http\Controllers\ProfileController@update | web,auth,guest |
| | GET|HEAD | profile/{profile} | profile.show | App\Http\Controllers\ProfileController@show | web,auth,guest |
| | GET|HEAD | profile/{profile}/edit | profile.edit | App\Http\Controllers\ProfileController@edit | web,auth,guest |
有人可以帮助我吗?
Tks,
阿吉亚尔,阿德森 M.
【问题讨论】:
-
欢迎来到 SO ...您知道资源会为您注册相同的
edit路由吗?你也在使用App\User进行身份验证吗? -
奇怪的是你的路由同时应用了 auth 和 guest 中间件...你确定你已经登录并且有一个 auth()->user() 吗?
标签: php laravel routes controller http-status-code-404