2016-09-15 4 views
0

간단한 양식을 만든 다음 오류가 있습니다.
routes.phpERROR TokenMismatchException in VerifyCsrfToken.php

Route::resource('/posts','PostsController'); 

가 PostsController

public function create() 
{ 
    return view('posts.create'); 
} 
public function store(Request $request) 
{ 
    return $request->all(); 
} 

create.blade.php

@extends('layouts/aap') 

@section('content') 
    <form method="post" action="/posts"> 
     <input type="text" name="title" placeholder="Enter Title"> 

     <input type="submit" name="submit"> 
    </form> 


@yield('footer') 

는 ** 난 제목이 데이터를 제출 싶어 ** 내가 제출 단추를 누르면 난이있어 오류 enter image description here

iam beginner 누구든지 나를 도울 수 있습니다!

답변

0

제거 할 수 verifcation 당신은 CSRF이 필요하지 않은 경우 :

Illuminate\Foundation\Http\Middleware\VerifyCsrfToken 

/app/Http/Resquests/Kernel.php

에서 당신이 CSRF verifcation 당신이 양식에 숨겨진 필드를 추가 할 수 있습니다 필요한 경우 :

<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>" /> 

또는 모든 프로젝트의 기본 레이아웃에 메타 태그를 추가 할 수 있습니다.

<meta name="csrf-token" content="<?php echo csrf_token(); ?>" /> 
+0

내가 csrf 확인에 대해 설명 할 수 있습니까? iam이 하나의 튜토리얼을 따르므로 숨겨진 필드는 입력하지 않지만 코드는 작동합니다 **, 왜? ** –

+0

숨겨진 필드를 입력하면 소스에 해당 값이 표시됩니다 코드, 그럼 보안 문제? –

+0

나는 csrf 검증을 비활성화했기 때문에 그의 코드가 작동한다고 생각한다. 자세한 내용은 https://laravel.com/docs/5.3/csrf에서 확인할 수 있습니다. 숨겨진 필드를 추가하면 laravel이 각 활성 사용자 세션에 대한 csrf 토큰을 생성하기 때문에 보안 문제가 발생하지 않습니다. –

관련 문제