Laravel conditional for @extends in blade

I have a Laravel app that has multiple users.  Depending on the user I need to display a different blade template.  The problem is that it is not possible to use a regular

@if($role == $something)
  @extends('layout.app')
@else
  @extends('layout.other')
@endif

After much searching I found that @extends is required to be on the first line so it is possible to have a conditional if you do it this way.

@extends($var ? 'layout.app' : 'layout.other')

Hope this saves you some time.

Leave a Reply

Your email address will not be published. Required fields are marked *