亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 laravel post 中自定義 url/slug

如何在 laravel post 中自定義 url/slug

PHP
嗶嗶one 2023-05-26 16:14:18
我試圖讓我的網站 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


查看完整回答
反對 回復 2023-05-26
  • 1 回答
  • 0 關注
  • 125 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號