Answer the question
In order to leave comments, you need to log in
If you need to get data from many models in one Laravel controller, what is the best way to group the code?
Hello.
Suppose I need to receive and send data from the Car, Wheel, Glass, Door models in the IndexController to the view - how is it customary to do:
- Just receive all the data in one function and send it to the view?
- Or write a separate function of the getCars type for each model - and then call these functions inside the method that is registered in the router, and still send them to the view?
How do you usually do this and why?
Thank you.
Answer the question
In order to leave comments, you need to log in
If the code is not repeated, then in one method and send to the view.
If it repeats within the controller, I put it in a separate method
public function getUsers()
{
return User::all();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question