Laravel – variable exists in the blade directive

@isset($checkvariable )
    <p>Your data is here!</p>
@endisset
@if(empty($checkvariable ))
    <p>Data does not exist</p>
@else
    <p>Your data is here!</p>
@endif

For Laravel 5.7 onwards use.

{{ $checkvariable ?? 'not-exist' }}

For Laravel version <5.7

{{ $checkvariable or 'not-exist' }}

Sample-1:

@if( !empty($data['var']))
   {{ $data['var'] }} 
@endif

Sample-2:

{{ $data['var'] or 'no data found' }}

Sample-3: Using ternary operator

<a href="" class="{{ ( ! empty($data['var'] ? $data['var'] : 'no data found') }}">

 

Forms -> Select options

<select name="type2" class="form-control">
  <option value="">Select an Option</option>
    @foreach( $fields as $field )
      @if ($field->field == 'type2')
        <option value="{{ $field->field_slug }}"
        @if ( $prospect->prison->rep_type2 == $field->field_slug ) 
          selected
        @endif
        >{{ $field->field_name }}
        </option>
      @endif
    @endforeach
</select>

Was this article helpful?

Related Articles

Leave A Comment?