Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

checking variable is null in laravel blade file

I have the variable $material_details->pricing=null I want to check the variable is set in laravel blade file.I have tried as

@isset($material_details->pricing)
 <tr>
   <td>price is not null</td>
 </tr>
@endisset

but no luck .How to check the variable is set or not in laravel 5.3 blade file.

like image 975
user3386779 Avatar asked Dec 11 '18 06:12

user3386779


People also ask

How do you check if a variable is empty in Laravel blade?

If you want to check if the variable exists, use isset otherwise use empty if the variable will always be set and you want to determine if its value is falsey.

How check variable is null or not in Laravel?

How check variable is NULL or not in laravel? The is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.

IS NOT NULL PHP Laravel?

The IS NOT NULL condition is used in SQL to test for a non-NULL value. It returns TRUE if a non-NULL value is found, otherwise it returns FALSE. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.


1 Answers

You can either use

null coalescing operator: {{ $material_details ?? 'second value' }}

or elvis operator: {{ $material_details ?: 'default value' }} (checks given value is empty or null)

Read on Elvis and Null coalescing operator.

Links:

Elvis: https://en.wikipedia.org/wiki/Elvis_operator

Null coalescing operator: https://en.wikipedia.org/wiki/Null_coalescing_operator

like image 60
usrNotFound Avatar answered Sep 24 '22 19:09

usrNotFound