Hello Friends 👋,
Welcome To Infinitbility! ❤️
Many devs use count()
method to check record exist or not in table and some are use get()
method but laravel provide exist()
and doesntExist()
method to check record exist or not.
This article provide example to use exist()
and doesntExist()
method in laravel
let’s start today topic Laravel exist and doesntExist query Example or how to check record exist or not in laravel.
Instead of using the count
method to determine if any records exist that match your query’s constraints, you may use the exists
and doesntExist
methods:
1if (DB::table('orders')->where('finalized', 1)->exists()) {2 // ...3}45if (DB::table('orders')->where('finalized', 1)->doesntExist()) {6 // ...7}
Thanks For Reading…
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.