【发布时间】:2020-10-02 18:08:17
【问题描述】:
我正试图让我的网站 slug/url 像这样 localhost:8000/apartment/example-post-cat-come 而不是 localhost:8000/example-post-cat-come
我有类似的类别 1. 公寓 2.平
我想在 url 中的 slug 之前添加帖子类别
目前我正在这样做
Route::get('/{post}','ShowPropertiesController@index')->name('posts.show');
在尝试了第一条路线后,我也做了以下事情
Route::get('{category}/{post}','ShowPropertiesController@index')->name('posts.show');
并在我的控制器中完成此操作
public function index($category, $post)
{
// ...
}
我收到此错误Missing required parameters for [Route: posts.show] [URI: {category}/{post}]. (View: C:\MAMP\htdocs\laravel-real-estate\resources\views\pages\welcome.blade.php)
这是我的刀
<a href="{{ route('posts.show',$properties->slug) }}">{{$properties->title}}</a>
如何让分类显示在 url 之前?
【问题讨论】:
-
如果第二条路线相同,为什么不能删除第一条路线(供您描述)?
-
我认为问题出在
welcome.blade.php,看来您忘记将参数传递给命名路由 -
我已经删除了它,那是我收到此错误
Missing required parameters for [Route: posts.show] [URI: {category}/{post}]. (View: C:\MAMP\htdocs\laravel-real-estate\resources\views\pages\welcome.blade.php) -
@RainDev 这是我的刀片
<a href="{{ route('posts.show',$properties->slug) }}">{{$properties->title}}</a>