DEV Community

Cleaner models with Laravel Eloquent Builders

Marinus van Velzen on September 05, 2021

Over the past few years I have created tons and tons of models in Laravel. These models have always blown up in size with tons of accessors and add...
Collapse
 
peter_brown_cc2f497ac1175 profile image
Peter Brown

Or we could all just learn SQL. An ORM is almost never the right idea. They were born out of people's fear of the database and unwillingness to learn PL/SQL, stored procedures, triggers and how to engineer a proper data access layer.

Collapse
 
bdelespierre profile image
Benjamin Delespierre • Edited

They were born out of people's fear of bla bla bla

This is innacurate. ORM exists for the sole purpose of facilitating modularity, reusability, and portability. Not having to worry about the DAL is a welcome bonus.

Collapse
 
peter_brown_cc2f497ac1175 profile image
Peter Brown

The only way that it's portable is if you're not using the database properly. If you're using the database properly then you're leveraging stored procedures triggers and a myriad of other database specific tools, scripts etc. The database is not simply a place to dump data. It should be the work horse of your DAL. Unfortunately, these days so many people don't even know how to write a line of database-side scripting.

Thread Thread
 
bdelespierre profile image
Benjamin Delespierre

Unfortunately, these days so many people don't even know how to write a line of database-side scripting.

Well then, we must ask ourselves why is it the case? I always found triggers & procedures difficult to code, to comprehend once they're in place (for most developpers, knowing a legacy project involves procedures is an immediate red-flag), and worst of all, to scale.

As powerful as they are, they're not helping most developers to get the job done. I mean, I could do my groceries math using linear algebra and get the same results, but is it helpful?

I believe ORM have been adopted far and wide because they're an objectively more ergonomic tool and, again, more portable. What if I wanted to install that cool CMS everyone uses but dang, it needs a specific RDBMS at a specific version?

I also believe there is a place for people with a real expertise of stored procedures, triggers, and all the database delicious features I clearly know nothing about. In their own place, I'm sure they're immensely helpful.

So, instead of demeaning the work of millions because in your eyes they aren't worthy, why not just live and let live?

Peace out.

Thread Thread
 
peter_brown_cc2f497ac1175 profile image
Peter Brown

I'm not demeaning the work of anyone. It is a fact that scripting done on the database is generally faster than scripting done on the server.. You can quantify it. You claim ignorance PL/SQL , but yet you claim to profess that it is cumbersome and unnecessary in most cases. You claim that it is a red flag. It is a red flag because most people don't take the time to learn it. Most people try to learn 50000 languages in instead of learning one scripting language 1 compiled language and 1 database and learning them completely. Unfortunately our education system as it is currently structured creates a sort of attention deficit in its manner of teaching. Gone are the days of repetition and rote memorization. Instead people today tend to flit around from topic to topic instead of gaining mastery in any one thing. Yes this is a judgment about the current state of the industry. It is not a condemnation of any individual. It is simply simply an observation from someone that has been in this industry for many years.. Do I learn new things? Certainly I do. But I also know that it is a firm understanding of the fundamentals that keeps us future proof and employed for the long haul.

Thread Thread
 
bdelespierre profile image
Benjamin Delespierre

Whatever float your boat mate. I hope you're happy with that kind of thinking.

I don't want to see more comments like this and I'm not interested in arguing with you. You are a bitter, old fashion person and you have no respect for opinions other than yours, so I'm blocking you.

Goodbye.

Collapse
 
ahmadmoussawi profile image
Ahmad Moussawi

Wow, clean and simple. Thanks for sharing

Collapse
 
yurich84 profile image
Yurich

Just curious, why not use traits?

Collapse
 
wblondel profile image
William Blondel

I was wondering the same