【发布时间】:2019-05-11 21:28:27
【问题描述】:
我对 Laravel 比较陌生,我发现自己一直在尝试显示类别 slug 而不是 ID。
eg: www.website/.../category-slug
我的网站目前显示 www.website/.../category-id。我有一个类别表和一个带有列的帖子表。
posts table = | id | title | body | img | post_category_id|
post_categories table = | id | name | catslug |
控制器
public function getPostCategory($id)
{
$postCategories = PostCategory::with('posts')
->orderBy('name', 'asc')
->get();
$posts = Post::orderBy('id', 'desc')
->where('post_category_id', $id)
->paginate(5);
return view('articles.category.categoriesposts')->withPosts($posts)->with('postCategories', $postCategories);
}
路线
Route::get('articles/category/{id}', [
'uses' => 'ArticlesController@getPostCategory',
'as' => 'pcategory'
]);
我尝试了很多方法,但似乎没有任何效果。任何帮助将不胜感激。
非常感谢,
灰
【问题讨论】:
标签: php laravel laravel-5 laravel-routing laravel-blade