我試圖讓我的網站 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 之前?
1 回答

RISEBY
TA貢獻1856條經驗 獲得超5個贊
問題出在 welcome.blade.php 中,你應該將所有必需的參數傳遞給路由:
<a href="{{ route('posts.show',['category' => CATEGORY, 'post' => POST]) }}">{{$properties->title}}</a>
使用您的值更改 CATEGORY 和 POST
- 1 回答
- 0 關注
- 125 瀏覽
添加回答
舉報
0/150
提交
取消