I am fairly new to laravel and i have found myself stuck trying to display category slugs instead of the ID
eg: https://ift.tt/2B7ONGa
my website currently shows https://ift.tt/2UysZwb
I have a categories table & posts table table with columns
posts table = | id | title | body | img | post_category_id|
post_categories table = | id | name | catslug |
**CONTROLLER**
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
return view ('articles.category.categoriesposts')->withPosts($posts)->with('postCategories', $postCategories);
}
**ROUTE:**
Route::get('articles/category/{id}', [
'uses' => 'ArticlesController@getPostCategory' ,
'as' => 'pcategory'
] );
I have tried so many methods but and nothing seems to work.
Any help would be really appreciated
Many thanks
Ash
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire