Reputation: 2599
I need to check if $request->link_description is null
then don't change anything or better to say don't touch the database column value.
is it possible to do so without doing an extra select query?
for example :
/** update ad Seat info */
$Update_Seat = AdSeat::where('id', $id)->where('owner_id', $owner_id)
->update(['seat_name' => $seat_name,
'seat_url' => $seat_url,
'logo_src' => ($logo_src) ? $logo_src : null,
'category_id' => $category_id,
'plan' => $plan,
'price_sale' => $price_sale,
'link_description' => ($link_description) ? $link_description : null,
'description' => ($description) ? $description : null,
'income_percentage' => $income_percentage,
'status' => STATUS_TO_APPROVE]);
I mean this part :
'link_description' => ($link_description) ? $link_description : null,
instead of null
I want to put something like :
'link_description' => ($link_description) ? $link_description : AdSeat::whereId(5)->value('link_description),
But as I said before I'm looking for a way to not to run extra select query like above.
Upvotes: 0
Views: 170
Reputation: 3226
It would be easier to build your data array before hand. Example:
// Do not add $link_description here
$data = [
'seat_url' => $seat_url,
...
];
// But add it if $link_description is not null
if (!is_null($link_description)) {
$data['link_description'] = $link_description;
}
$Update_Seat = AdSeat::...->update($data);
Upvotes: 2