Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if null and empty string in Laravel view

in my view I have to output separately the one that is null and the one that is empty string

so i have this:

@if( $str->a == null)
... // do somethin
@endif

@if( $str->a == '')
... // do somethin
@endif

the problem is they the same result.

Thanks

like image 624
i-faith Avatar asked Jul 21 '17 17:07

i-faith


1 Answers

In the comments you've said you only want to check if it is null. So, use is_null():

@if (is_null($str->a))
    // do somethin
@endif
like image 53
Alexey Mezenin Avatar answered Oct 01 '22 16:10

Alexey Mezenin