-
Notifications
You must be signed in to change notification settings - Fork 0
Laravel: General Tips
Oscar Fabiano edited this page Jul 6, 2021
·
1 revision
- IF YOU ARE NOT INSIDE A RESOURCE, BECAUSE WILL A QUERY FOR EACH ROW
$purchase = Purchase::where('id', $id)->with('details')->first();
$purchase->details
Do this:
$purchase = Purchase::where('id', $id)->first();
$purchase->details
Laravel will query the details when/if you need to use the details
Simplify with eloquent:
before:
$result = Transfer::where('id', $id)->get();
$result[0]
after:
$result = Transfer::find($id);
$result