Passing a fallback view in your @yield directive

Submitted by laraning - 6 years ago

If you have a @yield directive, you know that you can pass a default content in the 2nd argument. What if you want to pass the content of a view?

// You can have this:

@yield('repository')

// Or with a default content:

@yield('repository', 'nothing exists')

// And with a fallback view content:

@php
  $fallbackView = view('your.view.name')
@endphp

@yield('repository', $fallbackView)
  
// Voilá :)