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?
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?
You can do whatever you want, what is your question ?
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
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?
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community