I started working with Laravel about a month ago and I started by reading the documentation etc. Now I’m working on a project in Laravel 4.2 and I skipped some parts of the full documentation. In my current project I’m not using models and my fellow programmers tell me it’s good to use models. I know it’s pretty standard to just use models in a Laravel project and I’ve read parts of the documentation of models by now. I see it’s a clear way of working with tables etc. Now that I’m like in the middle of my project, I dont know if switching to models now, would be a big advantage. Since I have no experience with models. (So I have to learn it from the start). I’m currently doing everything in the Controllers. I cant see the disadvantage in using the query builder from Laravel in my controller instead of using the models. I do plan to eventually start other projects with models, but switching to models right now doesn’t seem like the best thing to do in the middle of my project.

This is a real project. I’m planning to get it online and people will actually use it.

Im still a student

So basically:

  • Is there a reason for me to switch to models in my current project?
  • Is there a difference in performance between my method and models?

3

The real question you would have to ask is, “Why should I use an MVC pattern”.
The reasons for using such a pattern can only be explained when one has an understanding of principles that programmers want to adhere to for a number of reasons, but maybe the most important one:

Seperation of concerns

The value of separation of concerns is simplifying development and maintenance of computer programs. When concerns are well-separated, individual sections can be reused, as well as developed and updated independently. Of special value is the ability to later improve or modify one section of code without having to know the details of other sections, and without having to make corresponding changes to those sections.

Source: Wikipedia

As described at the link I’ve posted, not implementing ‘some’ seperation of concern can, or will, lead to code being unreadable, unmanageable or worse – plain broken (examples? look for spaghetti-code or big-ball-of-mud)

Simple Example:

  • You’ve got a website in which books can be bought.
  • There are 26 different pages (controller methods) in which books are displayed, or in any way used (eg. Admins must add – edit – delete books, users must add-edit-delete comments on books, etc)

  • If you were to implement all your “book-logic” into each controller method then:

    1. All your controller methods will become larger and larger as books get more and more complex
    2. After a few weeks you want to change something about the way your books are displayed, you have to change all 26 different controller methods using them.
    3. After a while, you will have no idea where to find that line of code that makes sure that if a book is not for sale for a small period of time, it won’t be displayed by all your controllers that have anything to do with selling books
    4. Etc.
    5. After hacking in tons of small changes in all your controllers, you get the flue, or go on a long and (well-deserved) holiday just before a major bug – and some other programmer has to quickly find and resolve it without your help. Credits to him if he solved it in a timely fashion.

Note: this is just a stupid, quickly made up example with certainly enough flaws, but it is about the general picture.
Now, let’s think about our project when we’ve set all our book logic into 1 model that is reusable throughout all our pages. Simplified this means you’ll have to implement a change once, and that fact should answer your first question.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật