Mastering Laravel Artisan: A Comprehensive Guide to Command-Line Magic

Noor Yasser
5 min readSep 25, 2023

If you’re a Laravel web developer, you’re in for a treat. In this blog post, we’re going to demystify Laravel Artisan Commands — a handy tool that can make your web development tasks easier and more efficient.

Artisan is like a magic wand for developers, simplifying tasks and automating the boring stuff. Whether you’re a seasoned Laravel pro or just starting out, understanding Artisan can supercharge your development game.

In plain language, we’ll walk you through the essential Artisan commands, showing you how to use them effectively. You’ll learn how to create controllers, handle database migrations, and manage queues — all with a few simple commands.

So, if you’re ready to level up your web development skills, join us on this journey into the world of Laravel Artisan Commands. It’s time to make coding simpler and more fun!

  1. php artisan make:policy PostPolicy: This command generates a new policy file named PostPolicy. Policies are used to define authorization logic for specific actions on your application's resources.
  2. php artisan --help OR -h: Running this command with -help or h displays help information for a given artisan command.
  3. php artisan --quiet OR -q: This command suppresses all output messages.
  4. php artisan --version OR -V: It displays the current version of the Laravel application.
  5. php artisan --no-interaction OR -n: This command prevents any interactive questions when running artisan commands.
  6. php artisan --ansi: Force enabling ANSI output.
  7. php artisan --no-ansi: Disable ANSI output.
  8. php artisan --env: Set the environment in which the command should run.
  9. php artisan --verbose: Increase the verbosity of messages for debugging purposes.
  10. php artisan clear-compiled: Remove the compiled class file.
  11. php artisan env: Display the current framework environment.
  12. php artisan help: Display help information for a specific command.
  13. php artisan list: List all available artisan commands.
  14. php artisan tinker: Start an interactive shell for interacting with your application.
  15. php artisan down: Put your application into maintenance mode.
  16. php artisan up: Bring the application out of maintenance mode.
  17. php artisan optimize [--force] [--psr]: Optimize the Laravel framework for better performance. The -force flag forces the compiled class file to be written, and -psr is used to skip optimizing Composer dump-autoload.
  18. php artisan serve [--port 8080] [--host 0.0.0.0]: Serve the application on the PHP development server. You can specify a port or host if needed.
  19. php artisan app:name namespace: Set the application namespace.
  20. php artisan auth:clear-resets: Flush expired password reset tokens.
  21. php artisan cache:clear: Flush the application cache.
  22. php artisan cache:table: Create a migration for the cache database table.
  23. php artisan config:cache: Create a cache file for faster configuration loading.
  24. php artisan config:clear: Remove the configuration cache file.
  25. php artisan db:seed [--class[="..."]] [--database[="..."]] [--force]: Seed the database with records. You can specify the seeder class, database connection, and force the operation in production.
  26. php artisan event:generate: Generate missing events and event handlers based on registration.
  27. php artisan handler:command [--command="..."] name: Create a new command handler class. You can specify the command it handles.
  28. php artisan handler:event [--event="..."] [--queued] name: Create a new event handler class. You can specify the event it handles and whether it should be queued.
  29. php artisan key:generate: Set the application encryption key.
  30. php artisan make:command [--handler] [--queued] name: Create a new Artisan command. Use the -handler flag to generate a handler and -queued to make it queued.
  31. php artisan make:console [--command[="..."]] name: Create a new console command.
  32. php artisan make:controller [--plain] name: Generate a new resourceful controller class. Use -plain to generate an empty controller.
  33. php artisan make:event name: Create a new event class.
  34. php artisan make:middleware name: Generate a new middleware class.
  35. php artisan make:migration [--create[="..."]] [--table[="..."]] name: Create a new migration file. You can specify the table to be created or the table to migrate.
  36. php artisan make:model name: Create a new Eloquent model class.
  37. php artisan make:provider name: Generate a new service provider class.
  38. php artisan make:request name: Create a new form request class.
  39. php artisan migrate [--database[="..."]] [--force] [--path[="..."]] [--pretend] [--seed]: Run database migrations. You can specify the database connection, force the operation, and more.
  40. php artisan migrate:install [--database[="..."]]: Create the migration repository.
  41. php artisan migrate:refresh [--database[="..."]] [--force] [--seed] [--seeder[="..."]]: Refresh migrations, rollback, and re-run. You can specify the database connection, force the operation, and specify a seeder.
  42. php artisan migrate:reset [--database[="..."]] [--force] [--pretend]: Rollback all database migrations.
  43. php artisan migrate:rollback [--database[="..."]] [--force] [--pretend]: Rollback the last database migration.
  44. php artisan migrate:status: Show a list of migrations up/down.
  45. php artisan queue:table: Create a migration for the queue jobs database table.
  46. php artisan queue:listen [--queue[="..."]] [--delay[="..."]] [--memory[="..."]] [--timeout[="..."]] [--sleep[="..."]] [--tries[="..."]] [connection]: Listen to a specific queue, specifying various options like delay, memory limit, and more.
  47. php artisan queue:failed: List all of the failed queue jobs.
  48. php artisan queue:failed-table: Create a migration for the failed queue jobs database table.
  49. php artisan queue:flush: Flush all of the failed queue jobs.
  50. php artisan queue:forget: Delete a specific failed queue job.
  51. php artisan queue:restart: Restart queue worker daemons after their current job.
  52. php artisan queue:retry id: Retry a specific failed queue job by providing its ID.
  53. php artisan queue:subscribe [--type[="..."]] queue url: Subscribe a URL to an Iron.io push queue.
  54. php artisan queue:work [--queue[="..."]] [--daemon] [--delay[="..."]] [--force] [--memory[="..."]] [--sleep[="..."]] [--tries[="..."]] [connection]: Process the next job on a queue, with options for queue type, daemon mode, and more.
  55. php artisan route:cache: Create a route cache file for faster route registration.
  56. php artisan route:clear: Remove the route cache file.
  57. php artisan route:list: List all registered routes.
  58. php artisan schedule:run: Run the scheduled commands.
  59. php artisan session:table: Create a migration for the session database table.
  60. php artisan vendor:publish [--force] [--provider[="..."]] [--tag[="..."]]: Publish assets from vendor packages, specifying the provider and tag.
  61. php artisan tail [--path[="..."]] [--lines[="..."]] [connection]: Tail the application's log files, specifying the log path and number of lines to display.

--

--