As mentioned previously, Laravel is an MVC framework for the development of modern web applications. It is a software architecture standard that separates the representation of information from users' interaction with it. The architectural standard that it has adopted is not so new; it has been around since the mid-1970s. It remains current, and a number of frameworks still use it today.
The basic architecture of Laravel applications
Laravel directory structure
Now, let's look at how this pattern is implemented within an application with Laravel:
- Open the VS Code editor.
- If this is the first time you are opening VS Code, click on the top menu and navigate to File | Open.
- Search for the chapter-01 folder, and click Open.
- Expand the app folder at the left-hand side of VS Code.
The application files are as follows:
The MVC flow
In a very basic MVC workflow, when a user interacts with our application, the steps in the following screenshot are performed. Imagine a simple web application about books, with a search input field. When the user types a book name and presses Enter, the following flow cycle will occur:
The MVC is represented by the following folders and files:
MVC Architecture | Application Path | File | ||
Model | app/ | User.php | ||
View | resources/views | welcome.blade.php | ||
Controller | app/Http/Controllers | Auth/AuthController.php Auth/PasswordController.php |
Note that the application models are at the root of the app folder, and the application already has at least one file for MVC implementation.
Also note that the app folder contains all of the core files for our application. The other folders have very intuitive names, such as the following:
Bootstrap | Cache, autoload, and bootstrap applications |
Config | Application's configuration |
Database | Factory, migrations, and seeds |
Public | JavaScript, CSS, fonts, and images |
Resource | Views, SASS/LESS, and localization |
Storage | This folder has separated apps, frameworks, and logs |
Tests | Unit tests using PHPunit |
Vendor |
Composer dependencies |
Now, let's see how things work in the Laravel structure.