How to check column value of a record is null or not in laravel

Updated at 12-Sep-2021, By samar

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.

Back to code snippet queries related laravel