【发布时间】:2021-02-21 17:19:39
【问题描述】:
我有一个刀片模板,我在其中调用 show 方法的路由:
<div class="user"><a href="{{ route('profile.show',$user->id) }}"><div><img src="{{asset('images/user.svg')}}" alt=""></div></a></div>
该路由由资源控制器控制,路由设置如下:
Route::resource('profile', 'App\Http\Controllers\ProfileController')->middleware('auth');
从我的php artisan route:list 的输出中可以看到,该控制器的所有路由都已定义:
| | GET|HEAD | profile | profile.index | App\Http\Controllers\ProfileController@index | web |
| | | | | | auth |
| | POST | profile | profile.store | App\Http\Controllers\ProfileController@store | web |
| | | | | | auth |
| | GET|HEAD | profile/create | profile.create | App\Http\Controllers\ProfileController@create | web |
| | | | | | auth |
| | GET|HEAD | profile/{profile} | profile.show | App\Http\Controllers\ProfileController@show | web |
| | | | | | auth |
| | DELETE | profile/{profile} | profile.destroy | App\Http\Controllers\ProfileController@destroy | web |
| | | | | | auth |
| | PUT|PATCH | profile/{profile} | profile.update | App\Http\Controllers\ProfileController@update | web |
| | | | | | auth |
| | GET|HEAD | profile/{profile}/edit | profile.edit | App\Http\Controllers\ProfileController@edit | web |
| | | | | | auth |
到目前为止,控制器只有一个 dd 函数,因为我还没有开始编写它,而 show 方法是唯一一个已经编写任何东西的方法:
public function show($id)
{ dd($id);}
但由于某种原因,每当我尝试访问该路由时,它都会返回 404 Not Found 错误。我尝试访问 index 方法并且它可以工作,但是 show 方法总是返回 404 Not Found 错误。我也试过php artisan route:clear,但没有解决问题。我在这里做错了什么?
【问题讨论】:
-
php artisan route:clear再试一次,希望能解决您的问题 -
已经试过了,还是不行,不好意思,应该在帖子里说的。
-
您在路线列表中看到您的路线了吗?
php artisan route:list -
是的,都在那里
-
检查控制器显示功能,可能是 404 从那里引发
标签: laravel