laravel 5:扩展外观 [英] laravel 5 : Extend a Facade
本文介绍了laravel 5:扩展外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要根据客户端处理不同类型的数据库.
I need to handle different types of DB depending on the client.
我创建了一个名为 MyDBFacade 的Facade,可以在其中调用自己的函数.
I created a Facade called MyDBFacade where I can call my own functions.
例如:
MyDBFacade::createDBUser("MyUser"); // will create a DB user whatever I'm using Postgres or SQL Server
是否可以通过添加我自己的函数然后调用DB::createUser("MyUser")
的方式扩展Facade DB :: 框架?
Is there a possibility to extends the framework Facade DB:: in a way I could add my own functions and then call DB::createUser("MyUser")
?
任何线索或想法都将不胜感激.
Any clue or idea would be appreciate.
预先感谢,祝您有愉快的一天.
Thanks in advance, have a nice day.
推荐答案
假设您在app/Facades/MyDBFacade.php
<?php
namespace App\Facades;
use Illuminate\Support\Facades\DB;
class MyDBFacade extends DB
{
// ...
}
您只需要更改config/app.php
中的单行,
You just need to change single line in config/app.php
, from
'DB' => Illuminate\Support\Facades\DB::class,
到
'DB' => App\Facades\MyDBFacade::class,
这一切现在都应该起作用.
And it all should work now.
这篇关于laravel 5:扩展外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文