我是一只新拉维尔。我尝试在数据库中创建类别,但我在VerifyCsrfToken中遇到了TokenMismatchException的问题.php第67行:。遇到此问题后,我尝试将{{ csrf_field(( }}添加到我的表单中,但出现相同的错误。请帮我解决这个问题。谢谢
查看表单
{!! Form::open(array('action' => ['Page_Admin@updatemaincate', $main_cate->id], 'method' => 'PUT', 'enctype' => 'multipart/form-date')); !!}
{{ csrf_field() }}
<div class="modal-header" style="background:#3C8DBC;">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title" style="color:#fff;">New Main-Category</h4>
</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="form-group">
{!! Form::label('title', 'Title'); !!}
{!! Form::text('title', $value = $main_cate->title, $attributes = ['class' => 'form-control', 'name' => 'title']); !!}
</div>
</div>
</div> <!--end 12-->
</div> <!--end row-->
</div>
<div class="modal-footer custom-default">
{!! Form::submit('Edit', $attributes = ['class' => 'btn btn-default']) !!}
<button type="button" class="btn btn-default" data-dismiss="modal">No</button>
</div>
{!! Form::close(); !!}
控制器
public function maincategories()
{
$maincategory = maincategory::all();
return view('admin/maincategories', compact('maincategory'));
}
public function setmaincate(Request $request){
$this->validate($request,[
'title' => 'required'
]);
$tbl_maincate = new maincategory;
$tbl_maincate->title = Input::get('title');
$tbl_maincate->save();
Session::flash('success', 'Adding multiple images are successfully');
return Redirect('/maincategories');
}
路线
Route::get('/', 'Page_Admin@index');
Route::resource('admin', 'Page_Admin');
Route::get('maincategories', 'Page_Admin@maincategories');
Route::post('setmaincate', 'Page_Admin@setmaincate');
表单方法必须是"POST",可以使用{{method_field('PUT'(}}来设置方法
in Your app/Exceptions/Handler.php
将以下代码放入render
函数
//instance of Token Mismatched
if ($exception instanceof TokenMismatchException){
//redirect to a form. Here is an example of how I handle mine
return redirect($request->fullUrl())->with('csrf_error', $exception->getMessage());
}
在顶部使用以下行:
use IlluminateSessionTokenMismatchException;