Let's say there are three categories 1.Fruits 2.Books 3.Clothes.
And a table called posts
On my site.com/books i want to show all the posts that belong to category 1(that is books)
Here is the route
Route::get('/posts/books', 'PostsController@books'
I have the current code in my PostController Books Method
public function books(){$posts=Post::latest()->paginate('10);
return view('posts.books', compact('posts'));}
How to fetch records only from books category. Im learning laravel and would like to know how to fetch records from a single category with where statement
Thanks @burlresearch I understood now. Thanks its working. I saved category id and i was using where('category_id', '2'). I changed it to where('category_id, '2') and it worked.
Im used yii2 framework earlier so was used to where(category_id=2) code so getting confused. I guess ill read the whole documentation again.