Support the ongoing development of Laravel.io →
Laravel.io Architecture
Last updated 6 months ago.
0

The number of models should match the number of DB Tables (minus the pivot tables)

Last updated 6 months ago.
0

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.

Last updated 6 months ago.
0

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?

Last updated 6 months ago.
0

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();
Last updated 6 months ago.
0

Sign in to participate in this thread!

LaraJobs

Your banner here too?

Joe96 joe96 Joined 28 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.