php – Laravel Eloquent $model-> save()不保存但没有错误

php – Laravel Eloquent $model-> save()不保存但没有错误,第1张

概述更新我的Post模型时,我运行: $post->title = request('title');$post->body = request('body');$post->save(); 这不会更新我的帖子.但它应该根据the Laravel docs on updating Eloquent models.为什么我的模型没有更新? >我没有错误. >该帖子未在db中更新. >除了没有在数据 更新我的Post模型时,我运行:
$post->Title = request('Title');$post->body = request('body');$post->save();

这不会更新我的帖子.但它应该根据the Laravel docs on updating Eloquent models.为什么我的模型没有更新?

>我没有错误.
>该帖子未在db中更新.
>除了没有在数据库中更新,没有别的东西似乎奇怪.没有错误.行为正常.
> running this test to see if save succeeded的结果是真的.
> This Laravel thread没有帮助

发布模型:

class Post extends Model{    protected $fillable = [        'type','Title','body','user_ID',];   ....}

邮政控制人:

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与之前的帖子相同而没有更新的数据.

由于Laravel 5.5 laravel已经改变了一些验证机制,我想你需要尝试这种方式.
public function store(Request $request,$ID){    $post = Post::findOrFail($ID);    $valIDatedData = [];    // Request valIDation    if ($post->type == 1) {        // Post type has Title        $valIDatedData = $request->valIDate([          'Title' => 'required|min:15',]);    } else {      $valIDatedData = $request->valIDate([        'body' => 'required|min:19',]);    }    $post->update($valIDatedData);    return redirect('/');}
总结

以上是内存溢出为你收集整理的php – Laravel Eloquent $model-> save()不保存但没有错误全部内容,希望文章能够帮你解决php – Laravel Eloquent $model-> save()不保存但没有错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1258989.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存