Laravel - 数据库在保存时不更新

时间:2016-06-21 16:05:57

标签: php laravel laravel-5.2

我无法弄清楚为什么这不起作用。我检查了对象中的所有字段,它们正在被改变。该函数完成且没有错误,Session :: flash被更改但保存不更新数据库。任何帮助都会很棒。

public function confirmLeague($id, $authToken)
{
    $league = League::find($id);

    if ($league == null || $league->AuthToken != $authToken || $league->Validated)
    {
        Session::flash('error', 'The league does not exist.');
        return redirect('/');
    }

    $league->Validated = true;
    $league->save();

    Session::flash('success', 'The league has been added.');
    return redirect('/');
}

表脚本:

        Schema::create('leagues', function (Blueprint $table) {
        $table->increments('Id');
        $table->string('LeagueName', 250);
        $table->string('City', 50);
        $table->string('Province', 50);
        $table->string('Sport', 50);
        $table->string('Type', 10);
        $table->string('Website')->nullable();
        $table->string('Person', 100);
        $table->string('Phone', 20);
        $table->string('Email', 100);
        $table->string('Description', 250)->default('');
        $table->boolean('Validated')->default(FALSE);
    });

2 个答案:

答案 0 :(得分:0)

管理以解决问题。事实证明,laravel不喜欢数据库中列名中的大写字母。我只是将我的所有列重命名为小写,然后才能使用

答案 1 :(得分:0)

您可以简单地使用查询生成器而不是Eloquent,此代码直接更新数据库中的数据:)这是一个示例:

DB::table('post')
            ->where('id', 3)
            ->update(['title' => "Updated Title"]);

您可以在此处查看文档以获取更多信息:

http://laravel.com/docs/5.0/queries#updates

相关问题