Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VerifyCsrfToken.php第68行中获取TokenMismatchException_Php_Database_Laravel_Token_Crud - Fatal编程技术网

在VerifyCsrfToken.php第68行中获取TokenMismatchException

在VerifyCsrfToken.php第68行中获取TokenMismatchException,php,database,laravel,token,crud,Php,Database,Laravel,Token,Crud,我有简单的添加、编辑和删除方法,但随机出现以下错误: VerifyCsrfToken.php第68行中的TokenMismatchException 有时没有任何错误,我可以添加,编辑或删除,有时我得到的错误,我不知道为什么。由于我在表单中使用了csrf\u字段,所以出现了此错误 {{csrf_field()}} 这是我的密码。 路线: 索引视图: @if(Auth::check()) <div class="info-btn"> <a href="i

我有简单的添加、编辑和删除方法,但随机出现以下错误:

VerifyCsrfToken.php第68行中的TokenMismatchException

有时没有任何错误,我可以添加,编辑或删除,有时我得到的错误,我不知道为什么。由于我在表单中使用了
csrf\u字段
,所以出现了此错误

{{csrf_field()}}
这是我的密码。 路线:

索引视图:

@if(Auth::check())
    <div class="info-btn">
        <a href="info">Add</a>
        @if($info)
            <a href="{{action('InfoController@edit',$info->id)}}">Edit  </a>

            {!! Form::open(['action' => 
         ['InfoController@destroy',$info->id] , 'method'  =>  'DELETE']) !!}
            {{Form::token()}}
            {{form::submit('delete')}}
            {{Form::close()}}
        @endif
    </div>
@endif

如果确定传递了_令牌,则应检查正在使用的会话类型。默认情况下,laravel使用文件会话。我在使用重型ajax应用程序时遇到了这个问题,将会话驱动程序更改为数据库解决了我的问题

请在此处阅读更多信息:

如果这种情况不时发生,可能是由于会话超时。如果您尝试刷新页面,可以检查它。laracast讨论也一样。

你能检查并检查一下“令牌”是否被传递吗?我检查了我的表格,是的,我有“令牌”@siros,当
csrf\u令牌
不匹配时,会导致此异常。在控制器方法中,像
dd($request)
一样转储
请求
数组。并验证您在上述注释中提到的传递的
令牌是否与
控制器
方法中接收到的匹配。@siros,如果它们确实匹配,请尝试
php artisan配置:缓存
,有时这是由于旧的协同配置。只需尝试
{!!csrf_field()!!}
而不是
{csrf u field()}
,这应该行得通,大多数人都面临着同样的问题@sirosi使用默认值,我的项目是非常简单的带有CRUD的索引,仅此而已。我将会话更改为数据库时仍然出现错误:(您在哪个平台?请尝试检查文件夹chmod 777 storage/framework/sessions/(例如在linux中)中的权限)我使用windows 10并且仍然是本地的,实际上我检查了我的注册和登录表单,我得到了相同的错误。这很奇怪,因为昨天我没有任何错误。我在使用xampp和文件会话时遇到了类似的问题…xampp不会保持会话文件打开,令牌会重新生成,导致会话丢失和ajax请求上的相同错误…我的修复方法正在更改为文件会话我刚刚安装了laravel,目前工作正常。所有答案均为tnx:)
@if(Auth::check())
    <div class="info-btn">
        <a href="info">Add</a>
        @if($info)
            <a href="{{action('InfoController@edit',$info->id)}}">Edit  </a>

            {!! Form::open(['action' => 
         ['InfoController@destroy',$info->id] , 'method'  =>  'DELETE']) !!}
            {{Form::token()}}
            {{form::submit('delete')}}
            {{Form::close()}}
        @endif
    </div>
@endif
<form action="{{action('InfoController@store')}}" method="post">
    {{csrf_field()}}

    <div class="form-group">
        <label for="name">Name</label>
        <input type="text" name="name" class="form-control" id="name"}">
    </div>
        <label for="name">Slogan</label>
        <input type="text" name="add-slogan" class="form-control" id="slogan">
    </div>
    <div class="form-group">
        <label for="email">E-Mail:</label>
        <input type="mail" name="email" class="form-control" id="email">
    </div>
    <div class="form-group">
        <label for="phone">Phone :</label>
        <input type="text" name="phone" class="form-control" id="phone">
    </div>

    <button type="submit">Send Info</button>
</form>
<form action="{{action('adminInfoController@update',$edit_info->id)}}" method="post">
    {{csrf_field()}}
    {{method_field('PUT')}}
public function index()
{
    $info=Info::all()->first();
    return view('info-add',compact('info'));
}

public function store(Request $request)
{
    $name = $request->input('add-name');
    $slogan = $request->input('add-slogan');
    $email = $request->input('add-email');
    $phone = $request->input('add-phone');
    DB::table('data')->insert([
        'name' => $name,
        'email' => $email,
        'address' => $address,
        'phone' => $phone,
    ]);
    return redirect('/');
}

public function edit($id)
{
    $edit_info=DB::table('data')->where('id',$id)->first();
    return view('info-edit',compact("edit_info"));
}

public function update(Request $request, $id)
{
    DB::table('data')->where('id',$id)->update([
        'name' => $request->input('name'),
         'phone' =>$request->input('phone'),
         'email' =>$request->input('email'),
    ]);
    return redirect('/');
}

public function destroy($id)
{
    DB::table('data')->where('id',$id)->delete();
    return Redirect('/');
}