Method [header] does not exist on view - Laravel 5
<p>I have created a middleware to restrict the page going back inside the dashboard as follows:</p>

<pre><code>namespace App\Http\Middleware;

use Closure;

class ValidateBackButton {

/**
 * Handle an incoming request.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Closure  $next
 * @return mixed
 */
public function handle($request, Closure $next)            
    {            
            $response = $next($request);

            $response-&gt;header('Cache-Control','nocache, no-store, max-age=0, must-revalidate')
            -&gt;header('Pragma','no-cache') 
            -&gt;header('Expires','Sat, 01 Jan 1990 00:00:00 GMT');

            return $response;
    }
}
</code></pre>

<p>I have registered the middleware in app/http/kernel.php</p>

<pre><code>protected $routeMiddleware = [
    'auth' =&gt; 'App\Http\Middleware\Authenticate',
    'auth.basic' =&gt; 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
    'guest' =&gt; 'App\Http\Middleware\RedirectIfAuthenticated',
    'validateback' =&gt; 'App\Http\Middleware\ValidateBackButton',
];
</code></pre>

<p>I am using the middleware in my controller:</p>

<pre><code>public function __construct()
{
    $this-&gt;middleware('auth');
    $this-&gt;middleware('validateback');
}
</code></pre>

<p>Everything seems fine, however, i get the following error message:</p>

<blockquote>
  <p>BadMethodCallException in View.php line 387: </p>
  
  <blockquote>
    <p>Method [header] does not exist on view.</p>
  </blockquote>
</blockquote>

<p>Kindly help me out!</p>

<p><strong>UPDATE</strong></p>

<p>I think there should not be any problem with the view, so I've the layout file below. The code for view is too long to put it here.</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;!--[if IE 8]&gt; &lt;html lang="en" class="ie8 no-js"&gt; &lt;![endif]--&gt;
&lt;!--[if IE 9]&gt; &lt;html lang="en" class="ie9 no-js"&gt; &lt;![endif]--&gt;
&lt;!--[if !IE]&gt;&lt;!--&gt;
&lt;html lang="en" class="no-js"&gt;
&lt;!--&lt;![endif]--&gt;
&lt;head&gt;
&lt;meta charset="utf-8"/&gt;
&lt;title&gt;SB Admin v2.0 in Laravel 5&lt;/title&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
&lt;meta content="width=device-width, initial-scale=1" name="viewport"/&gt;
&lt;meta content="" name="description"/&gt;
&lt;meta content="" name="author"/&gt;

&lt;link rel="stylesheet" href="{{ asset("assets/stylesheets/styles.css") }}" /&gt;
&lt;/head&gt;
&lt;body&gt;
@yield('body')
&lt;script src="{{ asset("assets/scripts/frontend.js") }}" type="text/javascript"&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>