Update specific column after selecting on SelectColumn

So this is my code each of the selection have a seperate column for time_stamp, so if I select Order Created, the column order_created_time_stamp should be updated. How can I achieve that?
SelectColumn::make('order_status')
->options([
'Order Created' => 'Order Created',
'Processing' => 'Processing',
'Order En Route' => 'Order En Route',
'Order Arrived' => 'Order Arrived',
'Order Completed' => 'Order Completed',
'To Received' => 'To Received',
'Received' => 'Received',
])
->rules(['required'])
->disablePlaceholderSelection(),
SelectColumn::make('order_status')
->options([
'Order Created' => 'Order Created',
'Processing' => 'Processing',
'Order En Route' => 'Order En Route',
'Order Arrived' => 'Order Arrived',
'Order Completed' => 'Order Completed',
'To Received' => 'To Received',
'Received' => 'Received',
])
->rules(['required'])
->disablePlaceholderSelection(),
this is kinda what i want to do
$status = $record->order_status;

$timestamps = [
'Order Created' => 'order_created_time_stamp',
'Processing' => 'processing_time_stamp',
'Order En Route' => 'order_en_route_time_stamp',
'Order Arrived' => 'order_arrived_time_stamp',
'Order Completed' => 'order_completed_time_stamp',
'To Receive' => 'to_received_time_stamp',
'Received' => 'received_time_stamp',
];

$update = DB::table('orders')
->where('id', $record->id)
->update([$timestamps[$status] => ($status === $record->order_status) ? Carbon::now() : null]);

return $update;
$status = $record->order_status;

$timestamps = [
'Order Created' => 'order_created_time_stamp',
'Processing' => 'processing_time_stamp',
'Order En Route' => 'order_en_route_time_stamp',
'Order Arrived' => 'order_arrived_time_stamp',
'Order Completed' => 'order_completed_time_stamp',
'To Receive' => 'to_received_time_stamp',
'Received' => 'received_time_stamp',
];

$update = DB::table('orders')
->where('id', $record->id)
->update([$timestamps[$status] => ($status === $record->order_status) ? Carbon::now() : null]);

return $update;
3 Replies
Chrysippus
ChrysippusOP2y ago
btw the time_stamps are not showed on my table, should I just update them individually like I'll make the specific time_stamp column that is hidden and use updateStateUsing() ? I want to do something like afterStateUpdated() method but there's no method like that on table columns
Dennis Koch
Dennis Koch2y ago
I would probably do this via a model event.
Chrysippus
ChrysippusOP2y ago
I ended up doing this, thanks it works.
Want results from more Discord servers?
Add your server