2016-04-01 16 views
1

laravel 5:Yöntem - Ben şöyle pano içine geri dönüyor sayfayı kısıtlamak için bir ara katman oluşturduk

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->header('Cache-Control','nocache, no-store, max-age=0, must-revalidate') 
      ->header('Pragma','no-cache') 
      ->header('Expires','Sat, 01 Jan 1990 00:00:00 GMT'); 

      return $response; 
    } 
} 

Ben app/http/çekirdekte orta katman kayıt yaptıran

public function __construct() 
{ 
    $this->middleware('auth'); 
    $this->middleware('validateback'); 
} 

Her şey görünüyor: benim denetleyicisi ortakatmanını kullanıyorum

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

.php View.php hattı 387

BadMethodCallException: görünümünde mevcut değil

Yöntem [başlık] ince, ancak, aşağıdaki hata mesajı almak.

Lütfen bana yardım!

GÜNCELLEME

Ben görünümü ile herhangi bir sorun olmaması gerektiğini düşünüyorum, bu yüzden aşağıda düzeni dosyasını ettik. Görünüm kodu buraya koymak için çok uzun.

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

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

cevap

1

aşağıdaki değişiklikler sorunumu çözdü:

namespace App\Http\Middleware; 

use Closure; 
use Illuminate\Http\RedirectResponse; 

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 = $next($request); 

      $response = $response instanceof RedirectResponse ? $response : response($response); 

      return $response->header('Cache-Control','nocache, no-store, max-age=0, must-revalidate') 
          ->header('Pragma','no-cache') //HTTP 1.0 
          ->header('Expires','Sat, 01 Jan 1990 00:00:00 GMT'); // // Date in the past 

      return $response; 
    } 

} 
0

Sen header$next için zincirleme bu sorunu giderebilirsiniz:

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

bu yardımcı olmazsa, başka bir yerde header kullanılmadığından emin olun. Hata iletisinde, view() ile header kullanıyorsunuz. (Ayrıca, görünüm kodunuzu da gönderirseniz, yardımcı olabilirsiniz).

+0

sayesinde ancak hata oradan geliyor olabilir olarak o, görünümünüz için –

+0

Yayınla kodu yardımcı olmuyor. Özellikle, denetleyici görünümü nasıl oluşturuyor. –

+0

Düzen dosyasıyla güncelledim. Görünüm, düzenin gövde bölümündeki normal html dosyasıdır. –

İlgili konular