Why is better to have access to the whole database than just the model you want?
Laravel Eloquent vs C# entity framework
This question discusses the differences between the core way in which Laravel's Eloquent and C#'s Entity frameworks are used by the developer.
In Eloquent you create Model classes which extend Eloquent (or another class which extends Eloquent such as ValidationModel).
In Entity framework you have a central class which extends DBContext and this class lists a load of model classes using DBSet
In Eloquent you create an instance of a model class every time you need DB access in your code
In Entity framework you create an instance of the central class every time you need DB access in your code
In both cases there is a base class which interfaces with the database and provides lots of database functions. In both cases you have models to represent tables.
The difference is that Eloquent the models directly extend the database base class and are used directly every time you need DB access. In entity framework there is a middle class does these things.
Which way is better?
I would say the Entity framework way is better because it gives you access to the whole database every time you create an instance of the central class - creating an instance of a Laravel model only gives you access to that specific table and any relationships which have been defined.
creating an instance of a Laravel model only gives you access to that specific table and any relationships which have been defined.
@megaman7 …and thus leads to easier-to-reason code that deals with only the one specific part of the application you’re working with, satisfying the ‘S’ in ‘SOLID’ (the single responsibility principle).
Please or to participate in this conversation.