2017-03-01 31 views

答えて

1

一つの方法は、VerifyCsrfTokenを拡張していないの配列を持つことです内部にCSRFのURL:あなたはそこで詳細を見つけることができ

protected $middleware = [ 

    ... 

    'App\Http\Middleware\VerifyCsrfToken', 
]; 

<?php namespace App\Http\Middleware; 

use Closure; 
use Illuminate\Session\TokenMismatchException; 

class VerifyCsrfToken extends \Illuminate\Foundation\Http\Middleware\VerifyCsrfToken { 

    protected $except_urls = [ 
     'contact/create', 
     'contact/update', 
     ... 
    ]; 

    public function handle($request, Closure $next) 
    { 
     $regex = '#' . implode('|', $this->except_urls) . '#'; 

     if ($this->isReading($request) || $this->tokensMatch($request) || preg_match($regex, $request->path())) 
     { 
      return $this->addCookieToResponse($request, $next($request)); 
     } 

     throw new TokenMismatchException; 
    } 

} 

とカーネルの変更は、新たなミドルウェアを指すように

https://laravel.com/docs/5.1/routing#csrf-protection

Laravel 5: POST whithout CSRF checking

0

あなたはVerifyCrsfToken.phpクラスを変更することによって、および$ openRoutesを提供することにより、これを行うことができますし、基底クラスに触れたときにはい、あなたは火で演奏されます。 :)

//app/Http/Middleware/VerifyCsrfToken.php 

//add an array of Routes to skip CSRF check 
private $openRoutes = ['free/route', 'free/too']; 

//modify this function 
public function handle($request, Closure $next) 
    { 
     //add this condition 
    foreach($this->openRoutes as $route) { 

     if ($request->is($route)) { 
     return $next($request); 
     } 
    } 

    return parent::handle($request, $next); 
    } 
関連する問題