新建门脸Facade类

这一生的挚爱 提交于 2019-11-30 22:24:33

1.App\Contract目录下新建 CommonContract 类

 1 <?php
 2 namespace App\Contract;
 3 
 4 use Carbon\Carbon;
 5 use \Dimsav\Translatable\Translatable;
 6 
 7 /**
 8  * 通用函数封装类
 9  */
10 class CommonContract
11 {
12     /**
13      * 获取当前时间
14      */
15     public function gettime()
16     {
17         return Carbon::now();
18     }
19 
20 }

2.在App/Facades 下新建 CommonFacade 

 1 <?php
 2 namespace App\Facades;
 3 
 4 use Illuminate\Support\Facades\Facade;
 5 
 6 
 7 /**
 8  * 通用门面代理类
 9  */
10 class CommonFacade extends Facade
11 {
12     /**
13      * 
14      */
15     protected static function getFacadeAccessor()
16     {
17         return 'App\Contract\CommonContract';
18     }
19 }

3.config/app.php文件aliases数组注册服务提供者

1 'Common' =>App\Facades\CommonFacade::class,

4.在controller中引用

1 use Common;
2 
3 Common::gettime();

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!