Laravel much better of using if

- 1 answer

Ad

so most of time i do this

@if(!empty($variable)
  @if($variable == "yes")
      do something here
  @endif
@endif

well as you can see it really not a beautiful way, maybe (i really hope there is) a much simpler way to just detect if the variable is exist and not throwing error when it is not exist beside that...?

it making my code so crowded and if by anychance i forgot to add those will got beautiful error (well i design a eye cathing error page by the way)

@if(!empty($variable))
or 
@if(isempty($variable))
Ad

Answer

Ad

Combine the two checks into a single if statement:

@if (! empty($variable) && $variable == 'yes')
    do something here
@endif
Ad
source: stackoverflow.com
Ad