自定义助手函数
我新建了一个Helpers/helper.php文件  在composer.json中加入
"files":[
"App/Helpers/Helper.php"
]

更新映射
composer dump-autoload
路由:   除了在composer.json中配置之外也可以通过服务提供者来帮助实现。
app\Providers\AppServiceProvider.php
服务提供者中存在两个方法: register - 该方法是在框架执行中执行的方法,在 boot 方法之前执行。 boot - 在所有的 register 方法之后才会加载; 在 boot 和 register 中任选一个,输入下面的代码,即可调用自定义助手函数。
foreach (glob(app_path('Helpers').'/*.php') as $file){
require_once $file;
}
自定义 artisan
Artisan 是 Laravel 自带的命令行接口, 它提供了相当多的命令来帮助你构建 Laravel 应用。 你可以通过 list 命令查看所有可用的 Artisan 命令:
php artisan list
除 Artisan 提供的命令外,你也可以编写自己的自定义命令。命令在多数情况下位于app/Console/Commands 目录中。
创建文件
php artisan make:command 命令文件
$signature 属性:命令名称
$description 属性:命令描述
handle 方法:命令执行的内容
这些都是生成文件是自动生成的。
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class Hello extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:hello';
/**
* The console command description.
*
* @var string
*/
protected $description = '这里是是定义artisan命令的测试';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
echo '自定义artisan命令测试';
}
}
php artisan list 查看   也可以自定义一个创建文件的artisan的命令,像 php artisan make:controller TestController这样的命令。
<?php
namespace App\Console\Commands;
//创建文件的抽象类
use Illuminate\Console\GeneratorCommand;
class TestCommand extends GeneratorCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'make:Test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new file';
protected $type='Test';
/**
* 指定模板创建类
*/
protected function getStub(){
return __DIR__ . '/Stub/CreateTest.stub';
}
protected function getDefaultNamespace($rootNamespace)
{
return $rootNamespace.'/Tests';
}
}
在 App\Console\Kernel.php 中注册  在app\Console\commands 下面新建一个Stub\CreateTest.stub模板文件
<?php
namespace {{ namespace }};
class {{ class }}
{
public function test(){
return '模板创建成功';
}
}
执行命令:php artisan make:Test MyTest 创建文件  
|