jeudi 30 septembre 2021

How to alias in Laravel Eager Loading Array without changing method name

I need to alias when I do a Laravel eager loading:

$employee = Employee::with(['profilepic', 'emp_company'])->find($user->employee_id);

In my model I have profilepic function and emp_company function. I need to pass a company object without renaming the emp_company funtion to company.

I need to to this because I want the JSON response as profilepic and company. for the frontend I need emp_company object as company. It is possible to alias.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire