Setup a Laravel Project and Understand the Folder Structure

Setting up a Laravel project is an easy task.

We need to have the composer installed in our system. Then we need to download the Laravel installer, the command for installation is
composer global require “laravel/installer=~1.1”
if this does not works then we could just write
composer global require “laravel/installer”
and it would install the file.
Then we need to create a project and for this, we need to type
composer create-project –prefer-dist laravel/laravel blog “5.8”
if this does not works then we could just write
composer create-project –prefer-dist laravel/laravel blog
it would create a Laravel project named blog.

Soon after the project is created we now have to

Understanding the Folder structure

The most important thing in the Laravel project is understanding the structure of files and folders. Understanding the files and folder structure’s main purpose is to understand where we need to write codes for Html, Model, Controller, Routing, Filestore, Config, and Database.
The time after the Laravel project is created we see different folders and files. All the files and folder build while building the project have their use and gives it easy access while writing codes.
The main folder in the project consists of

Let’s take a brief look at the different folders created and the files in them.

The first one App mainly includes codes for HTML, Model, and Controller which are in folders shown below.

In the console directory, there is a kernel.php file that has codes for the custom command.
Exception folders have handler.php that includes all the codes for different exceptions.
The HTTP folder has 2 sub-folders namely controllers and middleware.

Controllers and Middleware mainly include files acting as a bridge between database and webpage. These include files for authentication login validation, registering ids, resetting the password, etc.

Cookies that are used to store some data of the user are also managed here. Controllers act as an interface between database and web-page and Middleware filters out the request.

The Model directory contains all of your model classes. It provides a beautiful, simple ActiveRecord implementation for working with your database. Each database table has a corresponding “Model” which is used to interact with that table. Models allow you to query for data in your tables, as well as insert new records into the table.

Then we have a Provider directory.

where we write different kinds of services like authentication services, routing services, and more.

Then we have Bootstrap directory that has an app.php file that helps in bootstrapping the application i.e loading the application on the browser.

Then we have a config directory that contains all the configuration files like database configurations, email configurations, session configurations, login configurations, catch configurations, and many more.

The database directory mainly includes three folders i.e factories, migrations, and seed.

Factories provide a convenient way to generate new model instances for  testing/seeding the application’s database. In Migrations, one database is shared with another database and also between developers. Seeding simply means putting the fake/dummy data in the database.

The public directory

has CSS, js, and more files that have predefined JavaScript and CSS of the project and most importantly index.php file. This is the first file that is loaded in the browser when our server (local server) is hosted.

The resource directory

is the important part where all the public files of HTML, CSS, js files are coded and sometimes local files. This directory most importantly includes views where we write the complete HTML. All the HTML pages that we want to display shall be placed here. These files can be placed directly or can placed inside the folder in views.

The route directory’s main purpose is placing the codes for URLs for the web as well as API.

The storage directory contains the app, framework, and log directory. The storage directory is used to store framework-generated files and caches. They also contain compiled Blade templates, file-based sessions, file caches, and other files generated by the framework and the log directory contains your application’s log files.

The test directory contains automated tests. We may run tests using the phpunit or php vendor/bin/phpunit commands.

Vendor directory stores all the package files which are installed by the composers.

In simple terms, the vendor directory acts as a store-keeper for all the package files for the project in laravel.

We have few more files that are necessary like environment file (env.php), composer file (composer.json), package file (package.json).

We use webpack.mix.js for integration of CSS and js files from different developers for effective use. It also serves as a better security for CSS and js files in the project so that it cannot be publicly accessed.

abhishek k
Tagged : / / / / / /
0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x