記錄下自己建立的Facades
1、建立一個類
<?php
namespace App\Wubuze\Plugs;
class Common
{
public function logInfo($msg)
{
file_put_contents(storage_path('logs/wbz-log'), $msg);
}
}
2、 建立一個Facade
namespace App\Wubuze\Facades;
/**
* @method static void info(string $message, array $context = [])
* @package App\Wubuze\Facades
*
*
* @see \App\Wubuze\Plugs\Common
*/
class Log extends \Illuminate\Support\Facades\Facade
{
protected static function getFacadeAccessor()
{
return 'wbz-plugs';
}
}
3、 在 AppServiceProvider 中 register
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Wubuze\Plugs\Common;
class AppServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton('wbz-plugs', function() {
return new Common;
});
}
}
4、 使用
App\Wubuze\Facades\Log::logInfo('Hello Facades');
本作品採用《CC 協議》,轉載必須註明作者和本文連結