First optionIn order for the fill
method to work, you must call $blog->save()
after this.
$blog->fill($request); $blog->save();
Also, when you use the fill
method, you are doing a bulk assignment. By default, Laravel protects you from bulk-assigned fields.
Open your Blog.php
model and add the fields you want to batch assign to the array $fillable
/** * 可以批量賦值的屬性。 * * @var array */ protected $fillable = [ 'title', 'description', ];
The second option is to use the update
method (don’t forget to also add fields to $fillable
in the model of the first option because ## The #update method is also a batch assignment field):
$blog->update($request);
The third option is to manually assign each field one by one, just like you did in the store method:
$blog->title = $request->title; $blog->description = $request->description; $blog->save();