Artisan the Laravel command line

Laravel has a simple and very powerful command line interface (CLI) known as artisan; artisan is nothing more than a file that is located in the root of our project with the name of ”artisan” and allows us to execute a series of pre-established commands; Of course, we can extend the commands offered by the framework itself by programming our own commands; but this is another topic; in short, we can divide the commands that we can use into three groups: 

Commands to generate files:

  1. Create migrations, we will talk about this in another chapter, but they are nothing more than files that save the structure of a table that the framework will map to the database.
  2. Generate seeds or seeds for test data.
  3. Generate drivers and other types of files.

Commands to handle processes:

  1. Set up a development server, in case you don’t want to use Apache or other servers supported by the framework.
  2. Run or return migrations.
  3. Clear caches.
  4. Manage the database.
  5. Run the migrations and seeds.

Commands to get project information:

  1. Command list.
  2. List of project routes.

Among other commands you can see running at the project level: 

$ php artisan

If you’re using Laravel Sail, and you don’t have PHP 8 installed at the OS level; you must run:

$ ./vendor/bin/sail artisan

And this is important to note, since it would be the way you should interact with artisan if you don’t have PHP 8 at the system level.

Most used commands

So you have a list of the commands; I recommend that you copy and read it a few times a day and become familiar with these commands that are the most used when developing in Laravel:

  1. php artisan make:controller: To create controllers.
  2. php artisan make:migration: To generate a migration file.
  3. php artisan migrate: To generate a migration and related as the rollback to return the migrations.
  4. php artisan routes: To see the routes of the application.

Do not worry if you do not understand the purpose of these functions, later we will see in detail the operation of each of these elements.

- Andrés Cruz

En español

This material is part of my complete course and book; You can purchase them from the books and/or courses section, Curso y libro Laravel 11 con Tailwind Vue 3, introducción a Jetstream Livewire e Inerta desde cero - 2024.

Andrés Cruz

Develop with Laravel, Django, Flask, CodeIgniter, HTML5, CSS3, MySQL, JavaScript, Vue, Android, iOS, Flutter

Andrés Cruz In Udemy

I agree to receive announcements of interest about this Blog.