We can do in controller
method save()
o find($id)
o update()
and create()
. How could I do that Model
have this responsibility ?
We can do in controller
method save()
o find($id)
o update()
and create()
. How could I do that Model
have this responsibility ?
Your question is a bit vague, but I think I understood your question.
How could you do that Model has this responsibility?
The model already has this responsibility. It is Eloquent that knows how to search with find
, create a new instance with create
and update it with save
or update
(has delete
also né).
The responsibility of Controllers methods is different. They should orchestrate the various steps of interacting with some CRUD command. They are usually composed of:
For each of these steps, Laravel presents several tools:
Of course this is a simplified view, but the idea is to make it clear that Controller's role is to orchestrate these steps and Model's role is just one of them.