How to check column value of a record is null or not in laravel
How to check column value of a record is null or not in laravel
In this tutorial, we will try to find the solution to "How to check column value of a record is null or not in laravel" through programming.
You can check if the column value of a record is null or not in laravel using whereNotNull() and exists() method. exists() method returns false if the column value of a record in the table is null and it returns true if column value is not null.-
Laravel whereNotNull() with exists() method to check if the column value is null or not
$hasImage = User::where('id', Auth::user()->id)->whereNotNull('image')->exists(); dd($hasImage);
Output :
true
or
false
It returns true if record does not have null value in column and return false if record have null value in column.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Command to create MySQL Docker image and access the MySQL command-line interface (CLI) within a running Docker container
- Trying to access array offset on value of type null error in laravel
- Count all and get 10 records after where condition in laravel
- How to pass query string to url in laravel
- Split an Eloquent Collection by half in Laravel
- The use statement with non-compound name 'Auth' has no effect
- Call to undefined method App\Models\User::follow()
- Illuminate\Database\QueryException could not find driver
- How to run a specific seeder class in laravel
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Get domain name in laravel
- How to get IP address in laravel
- How to pass query string with pagination in laravel
- Display option of select as selected with blade directive Laravel
- Get latest record by created at in Laravel
- How to validate website url in laravel using validaiton
- Send id with route Laravel
- Laravel route redirect not working
- How to create projects method with belongstomany relationship in user model
- How to get data from two tables in laravel
- Return view from route Laravel
- SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
- Input file with max size validation in laravel
- Credit card validation in laravel
- How to get database name in Laravel 9 ?