我创建了一个类和门面,如下所示:
Invoice.php(正面/Invoice.php)
<?php
namespace app\Facades\;
use Illuminate\Support\Facades\Facade;
class Invoice extends Facade
{
protected static function getFacadeAccessor()
{
//NEVER CALLED
dd("TEST");
return 'invoice';
}
}
?>
invoiceFacadeServiceProviders.php
<?php
namespace App\Providers;
use App;
use Illuminate\Support\ServiceProvider;
class InvoiceFacadesServiceProvider extends ServiceProvider
{
public function boot()
{
//
}
public function register()
{
App::bind('invoice',function()
{
return new \App\Invoice\Invoice;
});
}
}
?>
最后是课程本身:
<?php
namespace App\Invoice;
class Invoice
{
public function testfunc()
{
return "This is a test";
}
}
?>
在控制器中,我尝试使用如下类来测试它:
use App\Invoice\Invoice;
调用testfunc方法:
dd(Invoice::testfunc());
在
app.php
我添加了以下(提供程序):
App\Providers\InvoiceFacadesServiceProvider::class,
和(别名):
'invoice' => App\Facades\Invoice::class,
但我只得到:
Non-static method App\Invoice\Invoice::testfunc() should not be called statically.
我还注意到
getFacadeAccessor()
方法不会被激发,因为它没有命中
dd
我已经放在那里了。
我错过了什么?
感谢您的帮助和指导!