Laravel

Laravel TutorialChange default routing behaviour in Laravel 5.2.31 +CustomException class in LaravelDeploy Laravel 5 App on Shared Hosting on Linux ServerLaravel ArtisanLaravel AuthenticationLaravel AuthorizationLaravel Blade TemplatesLaravel CashierLaravel CollectionsLaravel Common Issues & Quick FixesLaravel ConstantsLaravel ControllersLaravel Cron basicsLaravel Cross Domain RequestLaravel Custom Helper functionLaravel DatabaseLaravel Database MigrationsLaravel Database SeedingLaravel Directory StructureLaravel DockerLaravel EloquentLaravel Eloquent : RelationshipLaravel Eloquent: Accessors & MutatorsLaravel Eloquent: ModelLaravel Error HandlingLaravel Events and ListenersLaravel Filesystem / Cloud StorageLaravel Form Request(s)Laravel Getting started with laravel-5.3Laravel HelpersLaravel HTML and Form BuilderLaravel InstallationLaravel Installation GuideLaravel Introduction to laravel-5.2Laravel Introduction to laravel-5.3Laravel lumen frameworkLaravel Macros in Eloquent RelationshipLaravel MailLaravel MiddlewareLaravel ObserverLaravel PackagesLaravel PaginationLaravel Permissions for storageLaravel PoliciesLaravel QueuesLaravel RequestsLaravel Route Model BindingLaravel RoutingLaravel SeedingLaravel ServicesLaravel SocialiteLaravel Task SchedulingLaravel TestingLaravel Token Mismatch Error in AJAXLaravel use fields aliases in EloquentLaravel Useful linksLaravel ValetLaravel ValidationMultiple DB Connections in LaravelNaming Files when uploading with Laravel on WindowsRemove public from URL in laravelSparkpost integration with Laravel 5.4



Laravel Directory Structure

From WikiOD

Change default app directory[edit | edit source]

There are use cases when you might want to rename your app directory to something else. In Laravel4 you could just change a config entry, here's one way to do it in Laravel5.

In this example we'll be renaming the app directory to src.

Override Application class[edit | edit source]

The directories name app is hardcoded into the core Application class, so it has to be overridden. Create a new file Application.php. I prefer to keep mine in the src directory (the one we'll be replacing app with), but you can place it elsewhere.

Here's how the overridden class should look like. If you want a different name, just change the string src to something else.

namespace App;

class Application extends \Illuminate\Foundation\Application
{
    /**
     * @inheritdoc
     */
    public function path($path = '')
    {
        return $this->basePath . DIRECTORY_SEPARATOR . 'src' . ($path ? DIRECTORY_SEPARATOR . $path : $path);
    }
}

Save the file. We're done with it.

Calling the new class[edit | edit source]

Open up bootstrap/app.php and locate

$app = new Illuminate\Foundation\Application(
    realpath(__DIR__.'/../')
);

We'll be replacing it with this

$app = new App\Application(
    realpath(__DIR__.'/../')
);

Composer[edit | edit source]

Open up your composer.json file and change autoloading to match your new location

"psr*4": {
    "App\\": "src/"
}

And finally, in the command line run composer dump-autoload and your app should be served from the src directory.

Change the Controllers directory[edit | edit source]

if we want to change the Controllers directory we need:

  1. Move and/or rename the default Controllers directory where we want it. For example from app/Http/Controllers to app/Controllers
  • Update all the namespaces of the files inside the Controllers folder, making they adhere to the new path, respecting the PSR-4 specific.
  • Change the namespace that is applied to the routes.php file, by editing app\Providers\RouteServiceProvider.php and change this:
protected $namespace = 'App\Http\Controllers';

to this:

protected $namespace = 'App\Controllers';

Credit:Stack_Overflow_Documentation