Category: Laravel, PHP, javascript

For instance, if we want to define a “one-to-one” relationship between Order and Customer model where the Order belongs to the User, you can define it like so. Here, the Eloquent will try to match the customer_id from the Order model to an id on the Customer model and based on that will fetch the records.

But there’s another way in Eloquent using which you can define relationships on-the-fly outside of the models.

Well, the answer is, you can define these relationships in the boot method of one of your service providers and you’ll good to go.

Follow me on Twitter @amit_merchant Define relationships outside of Eloquent models in Laravel How to detect fullscreen mode using CSS Fetch count of records for children relationships in Laravel Eloquent The difference between for...in & for...of in JavaScript Insert mass database records using model factories in Laravel
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners