The number of models should match the number of DB Tables (minus the pivot tables)
Yes models play big role, for example if you have a repeated code in controllers for a specific model why not move it into model. I hope you can understand where I am coming from any data implementation or structuring should go into model. You don't have to put everything into controller.
Watch this video Elementary Model View Controller (MVC) by Example https://www.youtube.com/watch?v=LiBdzE_DJn4.
TorchSK said:
The number of models should match the number of DB Tables (minus the pivot tables)
I don't see any difference between using a model to do
Vehicle::where('ID', '=', '1')->first();
and just using this
DB::table('vehicles')->where('ID', '=', '1')->first();
All that models do is connect to databases? Are they more secure than DB::table?
Maybe not much difference for that query but to me, the model version looks cleaner
Vehicle::with('colour')->whereHas('price', function($query)
{
$query->where('amount', '<=', '10000');
})->where('active', 1)->get();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community