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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners