Check if null and empty string in Laravel view

Viewed 136022

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

4 Answers

You can try this

@isset($str->a)
    // $str->a is defined and is not null...
@endisset

@empty($str->a)
    // $str->a is "empty"...
@endempty

If Statements Laravel docs

Related