Yield

Table of Contents

The yield keyword is a shorthand syntax for outputting a variable and also define the fallback content if it does not exists.

Example

Let’s say we want to display a variable containing some HTML markup and if it does not exists, we want to have some fallback markup.

Without yield
@if($slot.content)
  {{{ $slot.content }}}
@else
  <h2> Some fallback markup </h2>
@endif
With yield
@yield($slot.content)
  <h2> Some fallback markup </h2>
@endyield