Laravel artisan commands list


Laravel has awesome set of artisan commands, probably the most often used are make:xxx – like make:model or make:migration etc.

First, there is a command php artisan list which gives us all the commands, like this:

  make:auth              Scaffold basic login and registration views and routes
  make:command     Create a new Artisan command
  make:controller     Create a new controller class
  make:event            Create a new event class
  make:job                Create a new job class
  make:listener         Create a new event listener class
  make:mail              Create a new email class
  make:middleware  Create a new middleware class
  make:migration     Create a new migration file
  make:model           Create a new Eloquent model class
  make:notification  Create a new notification class
  make:policy           Create a new policy class
  make:provider       Create a new service provider class
  make:request         Create a new form request class
  make:seeder          Create a new seeder class
  make:test               Create a new test class


But it doesn’t give us any information about the parameters or options for these commands. So I want to make an overview of each of them here, starting with the most often used ones.

 make:controller

This command creates a new controller file in app/Http/Controllers folder.

Example usage:

php artisan make:controller StudentController
Parameters:

--resource
The controller will contain a method for each of the available resource operations – index(), create(), store(), show(), edit(), update(), destroy().


make:model

Create a new Eloquent model class.

Example usage:

php artisan make:model Student
Parameters:

--migration
Create a new migration file for the model.

--controller
Create a new controller for the model.

--resource
Indicates if the generated controller should be a resource controller.

you can do it like this:
php artisan make:model Student --migration --controller --resource
Or even shorter:
php artisan make:model Student -mcr

make:migration

Create a new migration file.

Example usage:

php artisan make:migration create_students_table
Parameters:

--create=Table
The table to be created.

--table=Table
The table to migrate.

--path=Path
The location where the migration file should be created.

make:seeder

Create a new database seeder class.

Example usage:

php artisan make:seeder StudentsTableSeeder

make:request

Create a new form request class in app/Http/Requests folder.

Example usage:

php artisan make:request Students


make:middleware

Create a new middleware class.

Example usage:

php artisan make:middleware CheckStatus


make:policy

Create a new policy class.

Example usage:

php artisan make:policy PostPolicy
Parameters:

--model=Photo
The model that the policy applies to.

make:auth

Example usage:

php artisan make:auth
Scaffold basic login and registration views and routes.

Parameters:

--views
Only scaffold the authentication views.

--force
Overwrite existing views by default.

make:command

Create a new Artisan command.

Example usage:

php artisan make:command SendEmails
Parameters:

--command=Command
The terminal command that should be assigned.

make:event

Create a new event class.

Example usage:

php artisan make:event StudentJoined
Parameters: none.

make:job

Create a new job class.

Example usage:

php artisan make:job SendReminderEmail
Parameters:

--sync
Indicates that job should be synchronous.

make:listener

Create a new event listener class.

Example usage:

php artisan make:listener SendStudentNotification
Parameters:

--event=Event
The event class being listened for.

--queued
Indicates the event listener should be queued.

make:mail

Create a new email class.

Example usage:

php artisan make:mail StudentJoined
Parameters:

--markdown
Create a new Markdown template for the mailable.

make:notification

Create a new notification class.

Example usage:

php artisan make:notification InvoicePaid
Parameters:

--markdown
Create a new Markdown template for the notification.

make:provider

Create a new service provider class.

Example usage:

php artisan make:provider HttpServiceProvider
Parameters: none.

make:test

Create a new test class.

Example usage:

php artisan make:test StudentTest

Comments

Popular posts from this blog

Laravel 5 Chart example using Charts Package

Laravel Stats Tracker

PHPMyBackup - A PHP MySQL differential backup script