Hello everyone,
I recently found out about APi resources in Laravel and I would like to take advantage of it. The problem is that it is extremely slow. I might be using them wrong. Here is my toArray function:
public function toArray($request)
{
return [
'id' => $this->id,
'business_unit' => isset($this->businessUnit) ? $this->businessUnit->en_label : null,
'company' => isset($this->company) ? $this->company->name : null,
'cost_center' => isset($this->costCenter) ? $this->costCenter->en_label : null,
'full_name' => isset($this->user) ? $this->user->fullName : null,
'function' => $this->function,
'is_active' => $this->is_active === 0 ? false : true,
'login' => isset($this->user) ? $this->user->login : null,
'manager' => isset($this->user->manager) ? $this->user->manager->fullName : null
];
}
As well as my index function:
public function index()
{
return EmployeeResource::collection(Employee::all());
}
A request can take up to 25 seconds to be completed.