为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 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 关注
  • 81 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信