Artisan, our best friend

Well, to start, artisan is based on Console component of Symfony. Let’s see what the documentation says about the Artisan.

Artisan is the command-line interface included with Laravel. It provides a number of helpful commands that can assist you while you build your application.

In this post we will focuses on most used commands from artisan. Artisan is nothing more than a php script that runs in console and can assist us in some boring and repetitive tasks.

If you use the list commands, you will see the complete list of available commands in artisan.

Like documentation says:

Every command also includes a “help” screen which displays and describes the command’s available arguments and options. To view a help screen, simply precede the name of the command with help:

Important notes

  • I advise you to see all commands with help to understanding more about the artisan;
  • You can create your own commands;
  • Commands are grouped by context;

The basic commands of artisan are:

  • help – Give the detailed description of the command
  • clear-compiled – when something goes wrong, use it to removes the caches
  • down – put the application in maintenance mode
  • up – put the application up again
  • env – show what environment is used by application
  • migrate – execute all database migrations
  • optimize – optimizes the application for better performance
  • serve – starts the PHP Built-in server
  • tinker – activates the REPL Tinker
  • preset – it’s a new command from Laravel 5.5 and helps you to start a application with React, Vue, Bootstrap or none of these.

Options

I divided the list of commands in 3 contexts according to MY OPINION.

Most used commands in development

  • cache:clear – Flush the application cache
  • db:seed Seed the database with records
  • event:generate Generate the missing events and listeners based on registration
  • migrate – Run the database migrations
  • tinker – Interact with your application
    • it’s ideal for little tests
  • make:controller – Create a new controller class
  • make:mail – Create a new email class
  • make:migration – Create a new migration file
  • make:model – Create a new Eloquent model class
  • make:policy – Create a new policy class
  • make:request – Create a new form request class
  • make:test – Create a new test class
  • migrate:rollback Rollback the last database migration
  • migrate:fresh Drop all tables and re-run all migrations
  • route:list List all registered routes
  • view:clear Clear all compiled view files
  • vendor:publish – Publish any publishable assets from vendor packages

Most unused but necessary commands

  • make:auth – Scaffold basic login and registration views and routes
    • Every application needs a begin
  • cache:table  – Create a migration for the cache database table
    • If you are using the cache in database
  • storage:link – Create a symbolic link from “public/storage” to “storage/app/public”
    • It allows you to use the storage in your public directory
  • session:table – Create a migration for the session database table
    • used if your application stores the sessions in database

Most used commands in production

  • auth:clear-resets Flush expired password reset tokens
  • config:cache – Create a cache file for faster configuration loading
  • config:clear – Remove the configuration cache file
  • route:cache Create a route cache file for faster route registration
  • route:clear Remove the route cache file

We have other important commands like queues, schedule, notifications but are complex to start understand it. I hope I’m not forget any important commands lol 😛

I hope you liked this post, see you soon 😉

Share this!




No Comments


You can leave the first : )



Leave a Reply

Your email address will not be published. Required fields are marked *

*