简体   繁体   English

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

[英]Laravel - Database not updating on save

I can't figure out why this isn't working. 我不知道为什么这不起作用。 I checked all the fields in the object and they are being changed fine. 我检查了对象中的所有字段,它们都被更改了。 The function completes without errors and the Session::flash gets changed but the save is not updating the database. 该函数无错地完成,并且Session :: flash被更改,但是保存未更新数据库。 Any help would be great. 任何帮助都会很棒。

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('/');
}

Table script: 表脚本:

        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);
    });

Managed to fix the issue. 设法解决了这个问题。 Turns out laravel doesn't like capital letters in the column names in the database. 事实证明,laravel不喜欢数据库中列名中的大写字母。 I just renamed all my columns to lowercase and it worked 我刚刚将所有列重命名为小写,就可以了

You can simply use Query Builder rather than Eloquent, this code directly update your data in the database :) This is a sample: 您可以简单地使用Query Builder而不是Eloquent,此代码直接更新数据库中的数据:)这是一个示例:

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

You can check the documentation here for more information: 您可以在此处查看文档以获取更多信息:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM