Useful Laravel Commands
Artisan
Command-line interface for Laravel. Symfony Console component.
Create Command
php artisan make:command <command-name>
Execute Commands
php artisan sitemap:generate # execute defined command
php artisan command:seedfunction /abc.csv # executre defined command with parameter
Defining the Custom Command
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Neighborhood;
use App\District;
use App\City;
class locationSeeder extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:seedneighborhoods {path : full path of the csv file}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This command will be used for once to add neighborhood data to the database';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
}
}
DB
Migration
php artisan make:migration create_users_table # create new migration file
php artisan migrate # execute the migration
php artisan migrate:rollback # rollback the latest migration