Hello this is my second article on laravel 5.2 tutorial. If you need to start learning how to install laravel 5.4 , please follow my tutorial here.
The default Laravel application structure is intended to provide a great starting point for both large and small applications. Of course, you are free to organize your application however you like. Laravel imposes almost no restrictions on where any given class is located – as long as Composer can autoload the class.
Laravel’s Directory Structure
When you open up a directory that contains a skeleton Laravel application, you’ll see
the following files and directories:
Let’s walk through them one by one to get familiar.
The root directory contains the following folders by default:
• app is where the bulk of your actual application will go. Models, controllers, route
definitions, commands, and your PHP domain code all go in here.
• bootstrap contains the files that the Laravel framework uses to boot every time
it runs. • config is where all the configuration files live.
• database is where database migrations and seeds live.
• public is the directory the server points to when it’s serving the website. This contains
index.php, which is the front controller that kicks off the bootstrapping process
and routes all requests appropriately. It’s also where any public-facing files
like images, stylesheets, scripts, or downloads go.
• resources is where non-PHP files that are needed for other scripts live. Views, language
• routes is where all of the route definitions live, both for HTTP routes and “console
routes,” or Artisan commands.
• storage is where caches, logs, and compiled system files live.
• tests is where unit and integration tests live.
• vendor is where Composer installs its dependencies. It’s Git-ignored (marked to
be excluded from your version control system), as Composer is expected to run
as a part of your deploy process on any remote servers.
The Loose Files
The root directory also contains the following files:
• .env and .env.example are the files that dictate the environment variables (variables
that are expected to be different in each environment and are therefore not
committed to version control). .env.example is a template that each environment
should duplicate to create its own .env file, which is Git-ignored.
• artisan is the file that allows you to run Artisan commands (see more Chapter 7) from
the command line.
• .gitignore and .gitattributes are Git configuration files.
• composer.json and composer.lock are the configuration files for Composer; composer.
json is user-editable and composer.lock is not. These files share some basic
information about this project and also define its PHP dependencies.
• gulpfile.js is the (optional) configuration file for Elixir and Gulp. This is for
compiling and processing your frontend assets.
• package.json is like composer.json but for frontend assets.
• phpunit.xml is a configuration file for PHPUnit, the tool Laravel uses for testing
out of the box.
• readme.md is a Markdown file giving a basic introduction to Laravel.
• server.php is a backup server that tries to allow less-capable servers to still preview
the Laravel application.
Laravel 5.4 Configuration
All of the configuration files for the Laravel framework are stored in the config directory. The config directory, as the name implies, contains all of your application’s configuration files. In this directory, you will find various files needed to configure database, session, mail, application, services etc.
Each of these files returns an array, and
each value in the array will be accessible by a config key that is comprised of the filename
and all descendant keys, separated by dots (.)
So, if you create a file at config/services.php that looks like this:
// config/services.php return [ 'sparkpost' => [ 'secret' => 'abcdefg' ] ];
you will now have access to that config variable using config('services.spark
Any configuration variables that should be distinct for each environment (and therefore
not committed to source control) will instead live in your .env files. Let’s say you
want to use a different Bugsnag API key for each environment. You’d set the config
file to pull it from .env:
// config/services.php return [ 'bugsnag' => [ 'api_key' => env('BUGSNAG_API_KEY') ] ];
This env() helper function pulls a value from your .env file with that same key. So
now, add that key to your .env (settings for this environment) and .env.example (template
for all environments) files:
Your .env file already contains quite a few environment-specific variables needed by
the framework, like which mail driver you’ll be using and what your basic database
Laravel provides facility to run your application in different environment like testing, production etc. You can configure the environment of your application in the .env file of the root directory of your application. If you have installed Laravel using composer, this file will automatically be created.
In case you haven’t installed Laravel, you can simply rename the.env.example file to .env file. A sample of Laravel .env file is shown below.
Note: The first line in the above image APP_ENV=local has been set. It can further be changed to production or testing as per your requirement.
The database of your application can be configured from config/database.php file. You can set configuration parameters that can be used by different databases and you can also set the default one to use.
Naming the Application
The App Directory, by default, is namespaced under App. To rename it, you can execute the following command and rename the namespace.
php artisan app:name <name-of-your-application>
Replace the <name-of-your-application> with the new name of your application that you want to give.
Start Laravel 5.4 Maintenance Mode
php artisan down
After successful execution, you will receive the following output −
It will activate the Maintenance mode and all the request to server will be redirected to a single maintenance page as shown in the following screenshot.
Stop Laravel 5.4 Maintenance Mode
php artisan up
After successful execution, you will receive the following output −
And now you will see the following in your browser:
Thanks And see you next part 🙂
Hi, My name is Masud Alam, love to work with Open Source Technologies, living in Dhaka, Bangladesh. I’m a Certified Engineer on ZEND PHP 5.3, I served my first five years a number of leadership positions at Winux Soft Ltd, SSL Wireless Ltd, Canadian International Development Agency (CIDA), World Vision, Care Bangladesh, Helen Keller, US AID and MAX Group where I worked on ERP software and web development., but now i’m a founder and CEO of TechBeeo Software Company Ltd. I’m also a Course Instructor of ZCPE PHP 7 Certification and professional web development course at w3programmers Training Institute – a leading Training Institute in the country.