Nowadays, it is common practice to create web applications by using the command line; and, with the evolution of web development tools and technologies, this has become very popular.
We will mention that NPM is one of the most popular. However, for the development of applications using Laravel, we have an advantage. The Artisan CLI is automatically installed when we create a Laravel project.
Let's look at what the official documentation of Laravel says about the Artisan CLI:
Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application.
Inside of the chapter-01 folder, we find the Artisan bash file. It's responsible for running all of the commands available on the CLI, and there are many of them, to create classes, controllers, seeds, and much more.
After this small introduction to the Artisan CLI, there would be nothing better than looking at some practical examples. So, let's get hands on, and don't forget to start Docker:
- Open your Terminal window inside the chapter-01 folder, and type the following command:
docker-compose up -d
- Let's get inside the php-fpm container and type the following:
docker-compose exec php-fpm bash
We now have all of the Artisan CLI commands available in the Terminal.
This is the simplest way to interact with the Teminal within our Docker container. If you are using another technique to run the Laravel application, as mentioned at the beginning of the chapter, you do not need to use the following command:
docker-compose exec php-fpm bash
You can just type the same commands from the next steps into the Terminal.
- Still in the Terminal, type the following command:
php artisan list
You will see the framework version and a list of all available commands:
Laravel Framework version 5.2.45
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
...
As you can see, the list of commands is very large. Note that the above code snippet, we did not put all the options available with the php artisan list command, but we will see some combinations on next lines.
- In your Terminal, type the following combination:
php artisan -h migrate
The output will explain exactly what the migrate command can do and what options we have, as seen in the following screenshot:
Output of php artisan -h migrate
It's also possible to see what options we have for the migrate command.
- Still in the Terminal, type the following command:
php artisan -h make:controller
You will see the following output:
Output of php artisan -h make:controller
Now, let's look at how to create the MVC in the Laravel application, using the Artisan CLI.