How to check column value of a record is null or not in laravel
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);0
It returns true if record does not have null value in column and return false if record have null value in column.
Random Code Snippet Queries: Laravel
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Send id with route Laravel
- Method Illuminate\Events\Dispatcher::fire does not exist
- Target class [HomeController] does not exist
- Submit form without CSRF token in Laravel
- Create a record if not exist in laravel
- How to add a key value pair to existing array in laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- How to use more than one query scope in Laravel
- Get last record from table in laravel
- Get products with number of orders in Laravel
- SQLSTATE: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- How to upload image in laravel 8
- How to generate .env file for laravel?
- Route [password.request] not defined
- Input file with max size validation in laravel
- If condition in foreach loop in laravel
- Call to a member function update() on null
- How to restore deleted records in laravel
- How to create projects method with belongstomany relationship in user model
- Extra Filter Query on Relationships in Laravel
- Create record with unique slug in laravel
- Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails
- Laravel csrf token mismatch for ajax POST Request
- Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0"