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 clone model
- How to delete record in Laravel with ajax
- Update if exist else insert new record in laravel
- Laravel 11 step by step instructions to upload file in storage directory and display in blade file
- Get only 10 records from table in laravel
- How to get date from created_at field in laravel
- Laravel form request validation
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- If condition in foreach loop in laravel
- Remove several global scope from query
- How to make Copy or Duplicate table row in laravel
- How to upload multiple images after preview in laravel using cropper js
- Laravel 9 route group with controller
- Call to a member function pluck() on array
- Insert dummy data in users table Laravel
- Get comma separated email from input array
- Laravel API response format
- How to get records in random order in laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- How to randomly get the user id from users table in laravel
- How to return a column with different name in Laravel
- Laravel csrf token mismatch for ajax POST Request
- Route prefix with auth middleware in laravel
- Symlink(): No such file or directory