Back

Is it possible to stack @if directives


Edgars posted 2 weeks ago

Hello, is it possible to create directive to use @if like this:

@if ($user->role == 'writer')
@if ($view == 'book')
  {{ $one }}
@else
  {{ $two }}
@endif
Tobias van Beek replied 2 weeks ago

It is transformed to normal ifs, so your example result in

<?php if ($user->role == 'writer') {?>
<?php if ($view == 'book') {?>
  <?php echo $one; ?>
<?php } else {?>
  <?php echo $two; ?>
<?php } ?>

But you can combine multiple checks in the same if. So if I correctly understand what you want:

@if ($user->role == 'writer' && $view == 'book')
  {{ $one }}
@else
  {{ $two }}
@endif

Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us