What is Artisan Console?
The PHP Framework for Web Artisans, Laravel, provides a command line tool called Artisan that can be used to perform various tasks, including database management. Artisan exists at the root of your application as the artisan script and provides a number of helpful commands that can assist you while you build your application.
This post it’s about commands to interacts to database, but if you want to see all commands you can run:
php artisan list
Below, we have some commands that are very useful to database management:
- php artisan migrate : This command will run any outstanding database migrations, which are used to modify the structure of the database.
- php artisan migrate:status : This command will display the status of all migrations, showing which ones have been run and which ones have not.
- php artisan migrate:rollback : This command will rollback the last batch of migrations that were run.
- php artisan migrate:reset : This command will rollback all migrations that have been run.
- php artisan migrate:refresh : This command will rollback and re-run all migrations.
- php artisan make:migration create_users_table : This command will create a new migration file in the database/migrations directory, which can be used to create a new table in the database. The name of the migration, in this case “create_users_table”, can be anything, and it’s used as a reference.
- php artisan db:seed : This command will run any seed files that have been defined in the database/seeds directory. Seed files are used to populate the database with test data.
- php artisan make:seeder UsersTableSeeder : This command will create a new seeder class in the database/seeds directory. This can be used to create data to database.
- php artisan db:seed –class=UsersTableSeeder : This command will run a specific seeder file
These are just a few examples of the many database-related commands that can be run using Artisan. You can also check the documentation for more details and more commands.