我試圖讓我的網(wǎng)站 slug/url 像這樣localhost:8000/apartment/example-post-cat-come而不是localhost:8000/example-post-cat-come我有這樣的類別 1. 公寓 2. 公寓我想在 url 中的 slug 之前添加帖子類別目前我正在做這個(gè)Route::get('/{post}','ShowPropertiesController@index')->name('posts.show');在嘗試第一條路線后我也做了以下Route::get('{category}/{post}','ShowPropertiesController@index')->name('posts.show');并在我的控制器中執(zhí)行此操作public function index($category, $post){ // ...}我得到了這個(gè)錯(cuò)誤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貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
問題出在 welcome.blade.php 中,你應(yīng)該將所有必需的參數(shù)傳遞給路由:
<a href="{{ route('posts.show',['category' => CATEGORY, 'post' => POST]) }}">{{$properties->title}}</a>使用您的值更改 CATEGORY 和 POST
- 1 回答
- 0 關(guān)注
- 152 瀏覽
添加回答
舉報(bào)
0/150
提交
取消
