Laravel 自定命令以及生成文件的例子
以創(chuàng)建service層為例子
1、執(zhí)行命令
php artisan make:command ServiceMakeCommand
2、在app\Console\Commands 下就會多出一個 ServiceMakeCommand.php 文件 ,更改其內(nèi)容為一下內(nèi)容 ( 注意:
1、承了GeneratorCommand類,
2、protected $signature = 'make:service {name}'; 中{name}必須要有
<?php
namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
class ServiceMakeCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:service {name}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a service';
/**
* Get the stub file for the generator.
*
* @return string
*/
protected function getStub()
{
return __DIR__.'/stubs/service.stub';
}
/**
* Get the default namespace for the class.
*
* @param string $rootNamespace
* @return string
*/
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'\Services';
}
}
3、創(chuàng)建模版
在 app\Console\Commands\ 下創(chuàng)建stubs文件夾 ,并創(chuàng)建文件service.stub,其內(nèi)容為
<?php
namespace DummyNamespace;
class DummyClass
{
public function __construct()
{
parent::__construct();
}
}
4、現(xiàn)在就已經(jīng)完成了,運行 php artisan list,就可以看到

執(zhí)行 php artisan make:service BaseService 就有BaseService.php 文件了

以上這篇Laravel 自定命令以及生成文件的例子就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
php解析url并得到url中的參數(shù)及獲取url參數(shù)的四種方式
本文給大家介紹php解析url并得到url中的參數(shù)及獲取url參數(shù)的四種方式,涉及到將字符串參數(shù)變?yōu)閿?shù)組,將參數(shù)變?yōu)樽址南嚓P(guān)知識,本文代碼簡單易懂,感興趣的朋友一起看看吧2015-10-10
Yii框架引用插件和ckeditor中body與P標簽去除的方法
這篇文章主要介紹了Yii框架引用插件和ckeditor中body與P標簽去除的方法,結(jié)合實例形式分析了Yii框架中引入插件的步驟、實現(xiàn)方法與相關(guān)注意事項,需要的朋友可以參考下2017-01-01
Laravel用戶授權(quán)系統(tǒng)的使用方法示例
這篇文章主要給大家介紹了關(guān)于Laravel用戶授權(quán)系統(tǒng)使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09

