How to check if database row exist in laravel?

Member

by brandy , in category: PHP Frameworks , 9 months ago

How to check if database row exist in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by wilmer.lemke , 9 months ago

@brandy 

You can check if a database row exists in Laravel by using the exists() method on an Eloquent model. Here's an example:

1
2
3
4
5
6
7
8
9
use AppModelsUser;

$user = User::where('email', 'john.doe@example.com')->first();

if ($user->exists()) {
    // Row exists
} else {
    // Row does not exist
}


In this example, we are checking if a user with the email address 'john.doe@example.com' exists in the database. The exists() method will return true if the row exists, and false if it does not.

Related Threads:

How to check if the record is exist in laravel?
How check if product exist in cart in shopify?
How to check if an element exist in array of array in php?
How to check whether image exist using chai or mocha?
How to get row number of a row in laravel?
How to delete a row in database using codeigniter?