laravel - 在 laravel 笔记工作中路由 /author/{username}
问题描述
嗨,我将此网址称为 http://127.0.0.1:8000/author/Tohidda,我看到 404 not found 错误。我使用这条路线但不工作!...我的路线和控制器是
Route::get('/author/{username}','UserController@author')->name('dashboard.author');
public function author(User $user , Course $course,$username)
{
$courses = Learning::with('course')->take(1)->latest()->get();
$categories = Category::where('parent','0')->get();
return view('Home.dashboard.author',compact('categories','user','courses','course','favorites'));
}
注意:Tohidda 我在用户表中的用户名
解决方案
该路线可能已正确访问。Laravel 引发 a404 是因为它找不到用户模型。您正在使用用户名访问用户,而默认情况下您应该使用id
用户的访问它。
您可以使用name
,但您需要指示 laravel 这样做。您需要将 定义name
为键。请参阅:https ://laravel.com/docs/7.x/eloquent#eloquent-model-conventions
推荐阅读
- bash - 如何使用 SFTP ls 命令显示子目录
- python - 如何在不转换任何其他语言字符的情况下在 python 中将重音字符串转换为英语中的非重音字符串?
- laravel - Laravel API 资源组按收集结果
- flutter - api调用颤动期间如何处理空安全?
- c++ - 如何围绕对象旋转相机而不以它为中心
- c# - 如何在 2 个参数之间使用具有 OR 关系的选项
- flutter - 要求用户连接到特定的 WiFi 颤振
- python - 如何处理 Python Selenium 身份验证窗口?
- woocommerce - 是否可以将“我的帐户”页面设为显示订单和运费的单页?
- excel - 如何在 Excel 中编写符合这些条件的公式