Best Approach to Laravel 5 Core Framework

So Laravel 5 creates a new folder structure and I'm trying to work out a better way to manage my custom classes (PhpSpec tests in mind)

I used to do something like this

  • Appendix
    • Apes (where my custom classes were saved)
    • Models
    • controllers
    • etc.

with the new structure, should I try to segment my classes to fit the new directory structure? For example, now there is an Http folder in the application, should I add the appropriate custom classes to that directory?

  • Appendix
    • Http
      • Apes
        • SomeHttpClass
      • Controllers
      • Middleware
    • Providers
      • Apes
        • MyServiceProvider
      • AppServiceProvider.php

I know this is probably a matter of personal preference etc., but I had a little trouble wrapping my head around what is best for creating a new L5 project.

Any guidance is appreciated.


After doing a little bit of tinkering, I settled on an approach that works great for me (this is a small application.

  • Appendix
    • Console
    • Handlers
    • Helpers
    • Http
      • Controllers
        • Administrator
        • Public
      • Middleware
      • Inquiries
    • Providers
    • Vaults
      • AbstractDbRepository.php
      • ClientRepositoryInterface.php
      • DbClientRepository.php
      • DbScheduleRepository.php
      • ScheduleRepositoryInterface.php
    • timetable
      • Exceptions
      • Schedule.php
      • ScheduleCalculator.php
      • ScheduleInputTransformer.php
      • ScheduleTimes.php
    • Traits
    • SimpleModel.php

I figured that if the model were fairly simple, I would just leave it in the root application, but for more complex models that require more extensive testing, I would use the repository pattern.

I just left the controllers in their original location, but they were split into admin / public. There is a chance that we will build a small API for this, and I will probably put everything related to the API in the app / Api


source to share

3 answers

At this point, the L5 is still undergoing significant changes. There is no "best approach" yet for how to do this, and the answer will change over time until L5 is actually released.

The reality is that you can do it in different ways and you will be fine. Taylor has always said that he structures an application for how you want it to behave - not because someone told you to do it that way.



Taylor Otwell laid out the structure of Usercapes Snappy on a blog:

Although it is based on Laravel 4.x, it is definitely worth reading.

Also the source code for has an interesting structure divided by domains:



You don't even need to stick to the standard way of placing controllers, views, or models, as most of them only need to change one line per file in the App folder. I did a simple file search for directory references that I wanted to change and quickly found this:

The default controller directory is set in the application /Providers/RouteServiceProvider.php:

protected $namespace = 'App\Http\Controllers';


In the same file, you can change the path to your route.php file:

public function map(Router $router)
    $router->group(['namespace' => $this->namespace], function ($router) {
        require app_path('Http/routes.php');


To change the path to the models, you just need to change the references to use the correct namespace in other files. For example, the User model is referenced in these files:

config / auth.php
config /services.php
database / factories / ModelFactory

Of course, you need to change the namespace in all moved files.



All Articles