Home > PHP Framework > Laravel > Avoid the trap! Laravel update data pitfalls

Avoid the trap! Laravel update data pitfalls

藏色散人
Release: 2020-11-23 14:50:16
forward
9644 people have browsed it

The following is the Laravel framework tutorial column to share with you the pitfalls of Laravel update data, I hope it will be helpful to friends in need!

Avoid the trap! Laravel update data pitfalls

Usually we have the following methods to update data:

Method 1

$model = Model::find($id);$model->field1 = $value1;$model->field2 = $value2;$model->save();
Copy after login

Method 2

Model::find($id)
    ->update([
        'field1' => $value1,
        'field2' => $value2,
    ]);
Copy after login

Method 3

Model::query()
    ->where('id', $id)
    ->update([
        'field1' => $value1,
        'field2' => $value2,
    ]);
Copy after login

All three methods can update data. If it were you, which method would you choose? Or which method has the best performance?                                                                                                                     

The above is the detailed content of Avoid the trap! Laravel update data pitfalls. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
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
Latest Issues
Composer cannot install laravel
From 1970-01-01 08:00:00
0
0
0
Laravel Space/laravel-backup cannot be installed
From 1970-01-01 08:00:00
0
0
0
Laravel 5.1 Login laravel comes with it No more
From 1970-01-01 08:00:00
0
0
0
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template