Laravel 3 : Looking for explanation how to use the model

房东的猫 提交于 2019-11-26 11:37:01

问题


I\'m new at MVC and my first framework is Laravel (3 for now). I\'ve started coding exclusively in the routes, and I moved to the controller. I\'m however doing all of my database operations in the controller. I do not understand how to use the model.

Examples either demonstrate everything in the controller or in the route, but they never split the model, controller and view.

Could anyone kindly explain me how to use the model? In short I don\'t understand how to link one to each other, like sending form input to them model, or processed data back to the controller.

A github repo of a Laravel (v3 if possible) with a full MVC setup would be nice to analyze too, if anyone has one up for me to look at?

Thanks.


回答1:


The best statement on the subject of Frameworks I've heard is due to Uncle Bob:

A good Architecture allows major decisions to be deferred!

Specifically:

  • A good Architecture delays choosing a Framework!

Another great piece to think about:

MVC is not an Architecture! It is a Delivery Design Pattern.

Watch his video - it is one of the sadly few ones out there that don't spend 1000 words on what can be said in 10 and I can't highly enough recommend it - and it will help you to understand many points raised in your question:

Robert C Martin(Uncle Bob) -Clean Architecture and Design - Video

Of course, his book on Clean Code is also highly recommended!




回答2:


Although this link is for Laravel 4 docs, it may help you understand how the models work - (Laravel 3 also uses Eloquent):

http://laravel.com/docs/eloquent

Also, specific to laravel 3:

http://codehappy.daylerees.com/eloquent-orm



来源:https://stackoverflow.com/questions/18773631/laravel-3-looking-for-explanation-how-to-use-the-model

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!