title: Laravel 5 redirect()->back() doesn't work as expected
body: <p>I've got a problem with <code>redirect()-&gt;back()</code> when there is no <code>HTTP_REFERER</code> set.</p>
  
  <p>Normally when I open my URL with an ID as parameter to show a specific datarow:
  <code>http://my-domain/module/ID</code></p>
  
  <p>If the specified <code>ID</code> is not existent or the current loggedin user has no permission to open it, I make</p>
  
  <pre><code>if (!$this-&gt;checkPermission($id)) {
      return redirect()-&gt;back()-&gt;withError('message');
  }
  // do my stuff to show the datarow
  </code></pre>
  
  <p>But when I change the browsers address field and load an non-permitted <code>ID</code> then there is no <code>HTTP_REFERER</code> set and <code>redirect()-&gt;back()</code> redirects me to my last loaded JavaScript <code>for_this_view.js</code> (and shows it) added in the view as following:</p>
  
  <p><strong>app.blade.php</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="de"&gt;
  &lt;head&gt;
      @section('head')
      &lt;meta charset="utf-8"&gt;
      &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  
      {!! HTML::style('assets/jquery-ui/jquery-ui.min.css?ver=1.11.4') !!}
      &lt;!-- some more scripts --&gt;
      @show
  &lt;/head&gt;
  
  &lt;body&gt;
      @yield('content')
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>show.blade.php</strong></p>
  
  <pre><code>@extends('app')
  
  @section('head')
      @parent
      {!! HTML::script('for_this_view.js') !!}
  @stop
  
  @section('content')
      &lt;!-- display datarow --&gt;
  @stop
  </code></pre>
  
  <p>What is <code>redirect()-&gt;back()</code> doing here?
  If there is no URL to redirect back laravel is guessing one? And why? Maybe to ever have a way to redirect.</p>
  
  <p>That make me not able to use this function.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Ah, maybe I found my problem...</p>
  
  <p>I've tried to dynamically load JavaScript's if they exist in a specific folder.
  I do that, because I want my JavaScript's be parsed like a view to get Blade Syntax in it. I added a specific folder to the <code>/config/view.php</code> and made files like <code>for_this_view_js.blade.php</code>. They are dynamically added as <code>for_this_view.js</code> in the <code>routes.php</code>.</p>
  
  <p>And therefore I made something like:</p>
  
  <pre><code>/* load view javascripts */
  /** @var \SplFileInfo $path */
  foreach (new RecursiveIteratorIterator(
          new RecursiveDirectoryIterator(public_path())
      ) as $path)
  {
      if ($path-&gt;isFile()
          &amp;&amp; ends_with($path-&gt;getFilename(), 'js.blade.php'))
      {
          Route::get('url_to_javascript.js', function() {
              $contents = View::make('for_this_view_js(.blade.php)');
              $response = Response::make($contents);
              $response-&gt;header('Content-Type', 'application/javascript');
              return $response;
          });
      }
  }
  </code></pre>