doujia9833
2018-07-03 09:53
浏览 59
已采纳

Laravel 5.6 - 只有在更改后才能保存

I have a Laravel 5.6 project and am trying to update a post from a form like this

<input name="email" type="text" class="form-control" placeholder="Email" value="{{$user->email}}" required>

In my PostsController I have this...

    if($request->input('email')) {
        $user->email = $request->input('email');
    }

I wanted it to only update the email if a new one has been input in the form, but because I am pre-populating the form fields it always passes the IF.

Is there a more Laravel way to do this? I have looked at isDirty() but I am not sure it is the correct thing to use.

图片转代码服务由CSDN问答提供 功能建议

我有一个Laravel 5.6项目,我正在尝试从这样的表单更新帖子 <前> &lt; input name =“email”type =“text”class =“form-control”placeholder =“Email”value =“{{$ user-&gt; email}}”required&gt; \ n

在我的PostsController中我有这个......

  if($ request-&gt; input('email)  ')){
 $ user-&gt; email = $ request-&gt; input('email'); 
} 
   
 
 

我只想要它 如果在表单中输入了新的电子邮件,则更新电子邮件,但由于我预填充表单字段,因此它总是通过IF。

是否有更多Laravel方法可以执行此操作 ? 我看过isDirty()但是我不确定它是否正确使用。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题