Check if collection exists.

Submitted by debjit - 4 years ago

Check if the collection exists or not.

$posts = Post::where('user_id',AUth::id());

if($posts->exists()){//Check if posts exists
$getAllPosts = $posts->get();//Get all the posts
}else{
return redirect()->back()->withError('No post found.');
}