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
- Laravel save object to database
- How to restore deleted records in laravel
- How to display order by null last in laravel
- Laravel 11 step by step instructions to upload file in storage directory and display in blade file
- Laravel route parameter
- How to get tomorrow and yesterday date in laravel
- Order by multiple columns in Laravel
- How to use bootstrap pagination in laravel 8
- Get today records in Laravel
- How to return error message from controller to view in laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- Submit form without CSRF token in Laravel
- Target class [admin] does not exist.
- Split an Eloquent Collection by half in Laravel
- Laravel order by date not working
- Get id of last inserted record in laravel
- How to get last year records count with month wise in Laravel
- Link storage folder in laravel 8
- How to add a key value pair to existing array in laravel
- After image selected get validation error in laravel
- How to add foreign key in laravel using migration
- How to create static page in Laravel
- How to prevent host header attack in Laravel
- Conditional where clause in Laravel
- How to pass query string with pagination in laravel