如何将模型中的附加列添加到数组中?
How can I get appended columns in model to array?
如何将模型中的附加列添加到数组中?
$ticket = Ticket::create([
'assigned_user_id' => $request->assigned_user_id,
'creator_id' => $request->creator_id,
'description' => $request->description,
'type' => $request->type,
'status' => Ticket::CREATED,
]);
flash(__('tickets.ticket_created_successfully'))->success();
$data = $ticket->refresh()->toArray();
return $data;
将 $ticket>refresh()->toArray();
更改为 $ticket->toArray();
我认为在这种情况下您不需要刷新模型。
阅读有关序列化到数组的更多信息 here
在 Laravel.
的官方文档中
如何将模型中的附加列添加到数组中?
$ticket = Ticket::create([
'assigned_user_id' => $request->assigned_user_id,
'creator_id' => $request->creator_id,
'description' => $request->description,
'type' => $request->type,
'status' => Ticket::CREATED,
]);
flash(__('tickets.ticket_created_successfully'))->success();
$data = $ticket->refresh()->toArray();
return $data;
将 $ticket>refresh()->toArray();
更改为 $ticket->toArray();
我认为在这种情况下您不需要刷新模型。
阅读有关序列化到数组的更多信息 here
在 Laravel.