2016-04-01 7 views
1

Laravel 5:方法 - 私は次のようにダッシュボードの内側に戻ってページを制限するためのミドルウェアを作成している

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; 
    } 
} 

は私がアプリ/ HTTP /カーネルにミドルウェアを登録しています

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

.PHP私は私のコントローラでミドルウェアを使用しています:

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

すべてがそうですView.phpライン387に

BadMethodCallException:ビューに存在しない

法[ヘッダー]細かい、しかし、私は、次のエラーメッセージを取得します。

助けてください!

UPDATE

私はビューに問題があってはならないと思うので、私は以下のレイアウトファイルをしました。ビューのコードが長すぎてここに入れることはできません。

<!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> 

答えて

1

次の変更は、私の問題解決:

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

あなたはheader$nextに連鎖することにより、この問題を解決することができます

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'); 

を、この問題が解決しない場合は、あなたが他の場所headerを使用していないことを確認してください。エラーメッセージからは、headerview()も使用しているようです。 (ビューコードを投稿すると助けになるかもしれません)。

+0

おかげが、エラーがあるから来ることができたとして、それは、あなたのビューの –

+0

郵便番号を助けていません。具体的には、コントローラがビューをレンダリングする方法。 –

+0

私はレイアウトファイルを更新しました。ビューは、レイアウトの本体セクションの下にある通常のhtmlファイルです。 –

関連する問題