Can I use call table view with model in laravel? How good practice is it? or is it preferable to call it with the DB selector?
Example = vusers / Model: User
Can I use call table view with model in laravel? How good practice is it? or is it preferable to call it with the DB selector?
Example = vusers / Model: User
More than good bad/practical I would say that it is a design decision in the architecture of the application, laravel (eloquent) is going to treat the view as a table.
Special consideration must be given to how the view is built to allow
updates
viewinginserts
: https://dev.mysql.com/doc/refman/5.7/en/view-updatability.htmlIn environments where several applications use the same database, it is usually convenient to define partial views to, for example, delegate role filtering to the database engine.
A classic example:
(*) application that only interacts with "student" users
By not using aggregation or group functions the view is "updateable" and behaves like a normal table so:
It then allows you to use wave:
In case you don't use a view you would have to explicitly use the filter by role, something like this:
And it derives in:
On the application side you avoid having to validate the role (which after all is only for students and not administrators for example), and on the database engine side you give it more work on what it knows how to do well and allows you to put extra restrictions, for example
WHERE rol='estudiante' AND tienetodopago='SI'
whereby the application already receives filtered data.Note: I put it together from memory so there may be some goofs, but basically yes, you can use views as tables in models (see insert and modify restrictions)