天天看點

【laravel】 @2 artisan指令建立檔案

author:咔咔

在項目開發時,使用指令建立檔案可以保障你的出錯率

首先使用php artisan make:command TestMake建立出自定義指令檔案

【laravel】 @2 artisan指令建立檔案
 然後複制一份架構建立檔案的源碼
【laravel】 @2 artisan指令建立檔案
 将裡邊所有的event改為server即可,切記區分大小寫,下面是一份源碼

<?php

namespace App\Console\Commands;

use Illuminate\Console\GeneratorCommand;

class ServerMakeCommand extends GeneratorCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:server';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new server class';

/**
* The type of class being generated.
*
* @var string
*/
protected $type = 'Server';

/**
* Determine if the class already exists.
*
* @param  string  $rawName
* @return bool
*/
protected function alreadyExists($rawName)
    {
return class_exists($rawName);
    }

/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
    {
return __DIR__.'/stubs/server.stub';
    }

/**
* Get the default namespace for the class.
*
* @param  string  $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
    {
return $rootNamespace.'\Server';
    }
}
      

然後需要建立模闆檔案server.stub

【laravel】 @2 artisan指令建立檔案