Laravel Check If Query Has Results Or Not

Hello devs,

In this laravel collection check if value exists tutorial, I will show you how we can check if collection property exists. To check if record exists in collection in laravel, laravel provides exists() eloquent method.

Using this exists() method, we can easily check if collection exists laravel. If you don't know laravel check if collection is empty, then this tutorial is for you. I am here to give you the complete solution of laravel check if key exists in collection.

Example code:

$post = Post::where('user_id',auth()->id())->exists(); // return true or false

   //collection exists

return redirect()->back()->withError('No post found.');


Read also: Way to Check Laravel Application Running Environment


Hope it can help you.


#laravel #laravel-8x #eloquent-tips #laravel-tips