laravel el equent问题当我使用where()之前()
在Laravel 8中,当我使用wery()之前()初始化条件之前使用Where()时!
例如;
$post = Post::find($id);
$post->update(['status' => 'published']);
此更新查询是:
update `posts` set `status` = 'published' where `id`='1'
但是当我使用where():
$post = Post::find($id);
$post->where('status', '=', 'unpublished')->update(['status' => 'published']);
更新查询时:
update `posts` set `status` = 'published' where `status`='unpublished'
但是我希望它像以下内容,
update `posts` set `status` = 'published' where `status`='unpublished' and `id`='1'
为什么这样的查询是这样的?我的期望错了吗?还是错误?
In laravel 8 and elequent when i use where() before update() initialize condition ereased!
for example;
$post = Post::find($id);
$post->update(['status' => 'published']);
this update query is:
update `posts` set `status` = 'published' where `id`='1'
but when i use where():
$post = Post::find($id);
$post->where('status', '=', 'unpublished')->update(['status' => 'published']);
update query is:
update `posts` set `status` = 'published' where `status`='unpublished'
But I expect it to be like the following
update `posts` set `status` = 'published' where `status`='unpublished' and `id`='1'
Why is the query like this? Is my expectation wrong? or is bug?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为您在
收集
上使用,而不是构建新查询。如果要使用特定属性值更新当前
$ post
,则需要使用而不是。It's because you are using
where
on aCollection
instead of building a new query.If you want to update the current
$post
with a specific value of an attribute you need to useif
instead.