Laravel app directory structure

In Previous post we have seen the advantages of using framework over no-framework. Also i mentioned why i choose Laravel among all. In this post we will see directory structure of the laravel app. I am talking about whole laravel project including laravel framework, but the app directory which is part of the laravel based web-application where most of the application components goes and developer will write code there.

Laravel Directory structure

You can see from the above picture app directory contains below sub directories.
commands: Will be used for declaring custom commands for artisan based cli interface.
config: Where all configuration files goes. Here you can find two important files, app.php and database.php. At beginner level you need to understand these two files. Config files are nothing but simple PHP array. In app.php
you will find all application related settings and in database.php you will find all database related settings.
controllers: This directory contains all the controller classes  used by our application. We will see how to wite controller in upcoming posts about laravel.
 
database: This directory contains database schema and seeder files generated by laravel CLI artisan utility.
lang: This directory contains all translation related files along with message_ids in common with all the languages. This directory may have sub-directories based on languages supported by application and sub-directories names are given based on language locale name.
library: This folder is not part of standard laravel app. But i have added it for common functions that will be used in my app. For this extra configuration in laravel app is required which we will see in future post because this topic is out of scope right now.
models:  This directory conains all the models classes used by the application. In laravel generally model class extends Eloquent class, so that model class can directly query to database table. We will see this in future post. But right now just understand the importance and usage of directory structure.
start: This directory contains 3 files, artisan.php, global.php and locale.php. Initially you don’t need to edit this files. But later on based your application you can modify it by understanding it from the laravel resources.
storage: This directory is used for storing and logs the application cache,sessions, logs and cached view templates. This directory contains 5 sub-directories, cache,logs,meta,sessions and views. We are not changing any file here. All files created here automatically by laravel to maintain logs, cache and sessions. But for we can refer logs for debugging when errors arises.
tests: This directory contains all the test-cases written to test application logic and other part. It is used for test driven development(TDD). If you are not using this approach please ignore it else try to use it when you know TDD.
views: This directory contains views of whole applications. Views nothing but application user interface.
There are other 3 directories at app level which are below
bootstrap: You can find application bootstrap logic here in start.php. There are also other two files you can find here which are autoload.php and paths.php which contains PHP autoload and paths related information respectively.
public: This is the directory where all our assets files goes like css, js and images. just create the folder as you need for your assets and you can use it in all your view files.
vendor: All the packages used by laravel framework.
Thanks
– Ahesanali Suthar
Advertisements

One thought on “Laravel app directory structure

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s