Support the ongoing development of Laravel.io →
posted 10 years ago
Architecture
Last updated 2 years ago.
0

DrPrez said:

Check these tutorials, they will answer your questions.. https://laracasts.com/series/laravel-from-scratch

I watched them... but it still makes no sense sometimes :)

Okay let's say i create a Model (app/models/Customer.php):

class Customer extends Eloquent {
}

So this model is only responsible for table 'customers' right?

But how exactely does it help me now?

Last updated 2 years ago.
0

DrPrez said:

It helps you because you can now access this model from any controller or view.

Yeah i could do fancy stuff like this now:

$customer = new Customer;
$customer->name = Input::get('customer');
$customer->save();

But i could do this also without the model:

DB::table('customers')->insert( array('name' => Input::get('customer')) );

Where is the "logic" inside the model? Doesn't it need one by default? Or is this optional?

Last updated 2 years ago.
0

You can do whatever you want, what is your question ?

Last updated 2 years ago.
0

The idea is a separation of concerns. Your model handles interactions with data and the controller handles requests.

Of course you don't need to do it that way but you'll be glad you did when your controller runs to 2000 lines of code and it's chock-a-block with database queries

Last updated 2 years ago.
0

pmall said: You can do whatever you want, what is your question ?

I just wanna know the best practice.

webbear1000 said: Of course you don't need to do it that way but you'll be glad you did when your controller runs to 2000 lines of code and it's chock-a-block with database queries

So what must be inside the Model? Everything that is related to the specific table?

Last updated 2 years ago.
0

You are overthinking. You chose to use laravel so have fun with Eloquent.

I mean the point of using a MVC framework is to use models, views and controllers.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Sharping sharping Joined 28 Jun 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.

© 2024 Laravel.io - All rights reserved.