// Geting the user
$profile = User::find(1); //the user_id
// Use User::model relation to Photo::model and save the photo options
$profile->photo()->update([$field => true, 'published' => true]);
Nov 16, 2017
2
Level 3
Sequential Database Query
Not sure if this is possible, but I think if it was that it would be a nice little hook. To call a save() or update() then do something all in one line.
$profile->photo()->where('avatar', true)->update([$field => false]);
$profile->photo()->where('id', '=', $id)->update([$field => true, 'published' => true]);
So for example right now I have to call this twice, update photo where its currently set to true to false THEN update a specific id to true
Is there a way to accomplish this with 1 query vs 2? Like below is the idea.
$profile->photo()->where($field, true)->update([$field => false])->then()->where('id', '=', $id)->update([$field => true, 'published' => true]);
Thanks
Dave
Please or to participate in this conversation.