title: Strange behavior when returning view with custom Blade directive in Laravel
body: <p>Currently I am working on a project where views need to be rendered through a custom Blade directive. However I came across a few (limitations?) errors I cannot solve (for a long time).</p>
  
  <p>My custom Blade directive with tree different ways to output a view.</p>
  
  <pre><code>Blade::directive('lwField', function ($expression) {
  
      // 1
      return view('lw::module.field.field')-&gt;render();
  
      // 2
      return Blade::compileString('{!! view("lw::module.field.field")-&gt;render() !!}');
  
      // 3
      return Blade::compileString('@include("lw::module.field.field")');
  
  });
  </code></pre>
  
  <p>The field view:</p>
  
  <pre><code>Get to the choppa!
  </code></pre>
  
  <p>The main view:</p>
  
  <pre><code>@extends('layout.default')
  
  @section('main_content')
  
      @lwField()
  
  @endsection
  </code></pre>
  
  <p>The layout file:</p>
  
  <pre><code>// ... some cool html
  
  @section ('main_content') 
  
  @show
  
  // ... even more cool html
  </code></pre>
  
  <p>The following happens when I execute the three methods separately:</p>
  
  <p><strong>1</strong> <code>return view('lw::module.field.field')-&gt;render();</code></p>
  
  <p>The fist time it executes it throws an error:</p>
  
  <pre><code>include(/somepath/storage/framework/views/b30c24f5b8fd420ef1a08edb52e92174e2dfe911.php): failed to open stream: No such file or directory (View: /somepath/resources/views/page/default.blade.php)
  </code></pre>
  
  <p>This is true since there is only one view in my cached folder:</p>
  
  <pre><code>// 5b27802352643346357e49b847d934736c36cd07.php
  // The main view with the field view
  &lt;?php $__env-&gt;startSection('main_content'); ?&gt;
  
      Get to the choppa!
  
  &lt;?php $__env-&gt;stopSection(); ?&gt;
  </code></pre>
  
  <p>The second time I run this it magically works. It will generate 3 other files:</p>
  
  <pre><code>// b30c24f5b8fd420ef1a08edb52e92174e2dfe911.php
  // the main view with yielding layout view without field view
  &lt;?php $__env-&gt;startSection('main_content'); ?&gt;
  
  &lt;?php $__env-&gt;stopSection(); ?&gt;
  
  &lt;?php echo $__env-&gt;make('layout.default', array_except(get_defined_vars(), array('__data', '__path')))-&gt;render(); ?&gt;
  
  // e4cec91e7d4adb5dac5c63e5bfa85ba9a258f664.php
  // the layout file
  // ...
  &lt;?php endforeach; $__env-&gt;popLoop(); $loop = $__env-&gt;getFirstLoop(); ?&gt;
  // ...
  
  // ffd60653d8490007c272c527abef3a5ede092a33.php
  // layout view and main view
  // ...
  &lt;?php $__env-&gt;startSection('main_content'); ?&gt;
  
  &lt;?php echo $__env-&gt;yieldSection(); ?&gt;
  // ...
  </code></pre>
  
  <p>It looks like it generates two files that are the same but one without the field view.</p>
  
  <p><strong>2</strong> <code>return Blade::compileString('{!! view("lw::module.field.field")-&gt;render() !!}');</code></p>
  
  <p><strong>3</strong> <code>return Blade::compileString('@include("lw::module.field.field")');</code></p>
  
  <p>These methods will return a blanko page and generate two files in cache without showing/logging any errors.</p>
  
  <pre><code>// 5b27802352643346357e49b847d934736c36cd07.php
  // Field view
  Get to the choppa!
  
  // b30c24f5b8fd420ef1a08edb52e92174e2dfe911.php
  // Main view and field view
  &lt;?php $__env-&gt;startSection('main_content'); ?&gt;
  
      &lt;?php echo view("lw::module.field.field")-&gt;render(); ?&gt;
  
  &lt;?php $__env-&gt;stopSection(); ?&gt;
  </code></pre>
  
  <p>This method will not generate the layout file.</p>
  
  <p>Does anyone have a clue on what is happening. Maybe this kind of behavior is not strange at all and this is how Blade should work.</p>