Home >Backend Development >PHP Tutorial >Laravel5.2 uses update to update data, why is created_at also updated?

Laravel5.2 uses update to update data, why is created_at also updated?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-06 13:52:421947browse

Execute function

<code>public function registerStore(Requests\RegisterRequest $request){
        $user=User::user();
        $res=$user->update($request->all());
        return redirect('/');
    }</code>

User.php

<code>    protected $fillable = [
        'name', 'email', 'password', 'openid','user_id','truename','tel','card','bank_name','bank_branch'
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
</code>

It is a very ordinary update, the user data is already available.

6.24 update, I set the extra value of the crated_at field in the user table to null, and it seems to be fine. Before, it was on update CURRENT_TIMESTAMP

Reply content:

Execute function

<code>public function registerStore(Requests\RegisterRequest $request){
        $user=User::user();
        $res=$user->update($request->all());
        return redirect('/');
    }</code>

User.php

<code>    protected $fillable = [
        'name', 'email', 'password', 'openid','user_id','truename','tel','card','bank_name','bank_branch'
    ];

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
</code>

It is a very ordinary update, the user data is already available.

6.24 update, I set the extra value of the crated_at field in the user table to null, and it seems to be fine. Before, it was on update CURRENT_TIMESTAMP

It seems that other people have encountered this problem: https://github.com/laravel/framework/issues/11518

Try creating migration when

<code class="php">$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();</code>

or

<code class="php">$table->nullableTimestamps();</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn