laravel - 路由返回错误 404 但路由存在
问题描述
我有一个刀片模板,我在其中调用了 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');
正如您从 my 的输出中看到的那样,定义了该控制器的所有路由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
,但没有解决问题。我在这里做错了什么?
解决方案
如果你试试这个?
<div class="user"><a href="{{ route('profile.show', ['profile' => $user->id]) }}"><div><img src="{{asset('images/user.svg')}}" alt=""></div></a></div>
推荐阅读
- c# - ASP.NET Core 3.0 未正确路由
- python - pandas大数据框的最佳实践(效率)数据操作
- ubuntu - 如何正确安装和运行 gdb?
- amazon-cloudformation - 在 CloudFormation 中为自定义资源引入条件
- vba - 将文件复制到另一个创建的文件夹
- swift - Xcode time profiler accuracy
- r - R:事后测试嵌套方差分析
- c# - C# Windows 窗体应用程序发送 html 格式的电子邮件
- scala - 怎么可能?Kafka队列中的重复记录?
- excel - 使用公式根据唯一键比较两个 Excel 表