在我的帖子模型中,我有这个:
public function getRouteKeyName()
{
return 'slug';
}
当我转到页面发布时,我的链接是:http://example.com/post/there-a-slug
我想要如何链接:http://example.com/post/id_post/there-a-slug
在我的路线上:
Route::get('/post/{post}', 'PostController@show')->name('showpost');
答案 0 :(得分:0)
您的路线如下所示:
Route::get('/post/{id}/{slug?}', 'PostController@show')->name('showpost');
而且您还必须在show
上更新PostController
函数
public function show(Request $request,$id,$slug=null)
{
//now you can find your post with id
$post=Post::findOrFail($id);
//your code goes here
}