Laravel Eloquent $model->save() 未保存但未出错
2022-08-30 12:42:58
						更新模型时,我运行:Post
$post->title = request('title');
$post->body = request('body');
$post->save();
这不会更新我的帖子。但根据Laravel关于更新Eloquent模型的文档,它应该这样做。为什么我的模型没有更新?
- 我没有收到任何错误。
 - 该帖子不会在数据库中更新。
 - 除了在数据库中没有更新之外,其他一切似乎都不奇怪。无错误。行为正常。
 - 运行此测试以查看
保存是否成功的结果为 。true - 这个Laravel线程没有帮助
 
Post型:
class Post extends Model
{
    protected $fillable = [
        'type',
        'title',
        'body',
        'user_id',
    ];
   ....
}
Post控制器:
public function store($id)
{
    $post = Post::findOrFail($id);
    // Request validation
    if ($post->type == 1) {
        // Post type has title
        $this->validate(request(), [
            'title' => 'required|min:15',
            'body' => 'required|min:19',
        ]);
        $post->title = request('title');
        $post->body = request('body');
    } else {
        $this->validate(request(), [
            'body' => 'required|min:19',
        ]);
        $post->body = request('body');
    }
    $post->save();
    return redirect('/');
}
奖金信息
运行返回 。dd($post->save())true
运行
$post->save();
$fetchedPost = Post::find($post->id);
dd($fetchedPost);
显示我与以前的帖子相同,没有更新的数据。$fetchedPost