We help IT Professionals succeed at work.

Could you point what parts of Laravel material (official or paralel) I must prefer to better improve my Eloquent knowledge - mainly fluid methods, if possible with some exercises?

Eduardo Fuerte
on
Hi Experts

Could you point what parts of Laravel material (official or paralel) I must prefer to better improve my Eloquent knowledge - mainly fluid methods, if possible with some exercises?

Thanks in advance
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
Hey Eduardo,

There are several different parts to really understanding Eloquent. I would definitely suggest you start off by reading (or re-reading the Official Docs). Often re-visiting the offical documentation after you've spent time working on something can be quite enlightening. You'll pick up on stuff that you missed the fisrt time your read through it.

There's also a few key concepts to understand to help you get the most out of Eloquent. One concept that I think escapes many people is that the Eloquent models are also Query Builders, so you can use any of the Query Builder commands on your Eloquent Models. Read up about the Query Builder to see what you can do

Often, when you retrieve Models from your Database, you will retrieve more than one instance of a Model. Laravel returns this list to you as a Collection, and Laravel Collections have there own set of methods that you can use, so read up on those also.

Eloquent : https://laravel.com/docs/6.x/eloquent
Query Builder : https://laravel.com/docs/6.x/queries
Collections : https://laravel.com/docs/6.x/eloquent-collections

Once you've got a good understanding of those concepts, you can chain the methods together.

Something else that isn't directly related to Eloquent, but will help you acheive cleaner code is a solid understanding of Relationships. Many modern Data Driven apps use data that is related to each other. Have a read up on Database Relationships so you can what we use them and what kinds of realtionships there are (one-to-one / one-to-many / many-to-many etc). Once you know that, have a read up on how Laravel implements these relationships. Building these directly into your Models will make your code a lot cleaner and allow you to use simple methods on your Models, instead of chaining together raw DB Joins!

Relationships : https://laravel.com/docs/6.x/eloquent-relationships

One final point I would make which may sound obvious - change the way you think about your data. In a traditional sense, we tend to think about our data as a series of Tables, Rows, Columns and we relate that data through a series of Primary Keys / Foreign Keys / Joins etc. We interact with that data using SQL queries for example. Having that understanding is helpful, but when you're dealing with an ORM such as Eloquent, it makes it easier to forget about data in those terms, and start thinking about them in an Object Oriented way. You have Models that represent your business entities (tables) and those Models have properties that descripe them (columns). Those Models may have a direct relationship to other Models (or collections of other Models) so you can add a Method or Property to access those related Models. Your entire application is mapped out as a series of Models.

Hope that all makes sense
Eduardo FuerteDeveloper and Analyst

Author

Commented:
Hey Chris

Very in depht guidance.

Eloquent imposes a innovative way of thinking... that's a challenge.

Still following it.
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
It certainly does encourage you to think in a different way, but once you do, it does become easier (in my opinion).

The more Object Oriented programming you do, the more intuitive an ORM like Eloquent becomes :)
Eduardo FuerteDeveloper and Analyst

Author

Commented:
Hi Chris


Thank you for the excelent guidance!

Now it's up to me to follow it.
CERTIFIED EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019

Commented:
Haha - that's my problem - I never follow my own advice :)

Good luck with it

Explore More ContentExplore courses, solutions, and other research materials related to this topic.