1、控制器(Controller) or 模型(Model)
// 創(chuàng)建一個空控制器
php artisan make:controller BlogController
// 指定創(chuàng)建位置 在app目錄下創(chuàng)建TestController
php artisan make:controller App\TestController
//創(chuàng)建model
php artisan make:model User //laravel會默認(rèn)在app目錄下創(chuàng)建model
// 指定路徑創(chuàng)建model
php artisan make:Model App\\Models\\User(linux or macOs 加上轉(zhuǎn)義符)
2、數(shù)據(jù)遷移(Migration)
// 創(chuàng)建遷移
php artisan make:migration create_users_table
// 指定路徑
php artisan make:migration --path=app\providers create_users_table
// 一次性創(chuàng)建
// 下述命令會做兩件事情:
// 在 app 目錄下創(chuàng)建模型類 App\Post
// 創(chuàng)建用于創(chuàng)建 posts 表的遷移,該遷移文件位于 database/migrations 目錄下。
php artisan make:model --migration Post
// 執(zhí)行數(shù)據(jù)遷移
php artisan migrate
//復(fù)位并重新運行所有的遷移
php artisan migrate:refresh
//回滾全部數(shù)據(jù)庫遷移
php artisan migrate:reset
//回滾最后一個數(shù)據(jù)庫遷移
php artisan migrate:rollback
3、數(shù)據(jù)填充(Seeder)
// 創(chuàng)建要填充的數(shù)據(jù)類
php artisan make:seeder UsersTableSeeder
// 數(shù)據(jù)填充(全部表)
php artisan db:seed
// 指定要填充的表
php artisan db:seed --class=UsersTableSeeder
4、路由(Route)
// 查看所有路由
php artisan route:list
//路由執(zhí)行緩存
php artisan route:cache
//路由清除緩存
php artisan route:clear
5、第三方依賴(Composer)
//配置Composer中國鏡像(CDN加速):
composer config -g repo.packagist composer https://packagist.phpcomposer.com
//更新Laravel依賴庫:
composer install || composer update
//自動加載
composer dump
6、配置(Config)
//清除Laravel配置緩存:
php artisan config:clear
//緩存配置
php artisan config:cache
7、任務(wù)調(diào)度(Command)
//執(zhí)行所有任務(wù)調(diào)度php artisan schedule:run
8、異步隊列(Jobs)
//進行下一個隊列任務(wù)
php artisan queue:work
//列出全部失敗的隊列工作
php artisan queue:failed
//創(chuàng)建一個遷移的失敗的隊列數(shù)據(jù)庫工作表
php artisan queue:failed-table
//清除全部失敗的隊列工作
php artisan queue:flush
//刪除一個失敗的隊列工作
php artisan queue:forget
//監(jiān)聽一個確定的隊列工作
php artisan queue:listen
//重啟現(xiàn)在正在運行的所有隊列工作
php artisan queue:restart
//重試一個失敗的隊列工作
php artisan queue:retry
9、 自定義artisan命令行
// 以下命令生成文件 app/Console/Commands/TestCommand.php
php artisan make:command TestCommand --command=test:command
//在 app/Console/Kernel.php 文件里面, 添加以下
protected $commands = [
Commands\TestCommand::class,
];
<?php
/**
* Created by PhpStorm.
* Users: wangsl
* Date: 2017/10/29
* Time: 17:07
*/
namespace App\Console\Commands;
use App\Models\Users;
use Illuminate\Console\Command;
class TestCommand extends Command
{
/**
* 1. 這里是命令行調(diào)用的名字, 如這里的: `topics:excerpt`,
* 命令行調(diào)用的時候就是 `php artisan topics:excerpt`
*
* @var string
*/
protected $signature = 'test:command';
/**
* 2. 這里填寫命令行的描述, 當(dāng)執(zhí)行 `php artisan` 時
* 可以看得見.
*
* @var string
*/
protected $description = '測試命令行的描述';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 這里是放要執(zhí)行的代碼
*
* @return mixed
*/
public function handle()
{
$users = Users::all();
$count = 0;
foreach ($users as $user) {
if (empty($users->remember_token)) {
$operate = Users::find($user['id']);
$operate->remember_token = md5(time() . "abcAbc");
$operate->save();
$count++;
}
}
$this->info("Saved remember_token count: " . $count);
$this->info("It's Done, have a good day.");
}
}
//運行命令
php artisan test:command
執(zhí)行結(jié)果

微信截圖_20181101173250.png