laravel 8 中的 Facades 在控制器文件中完美运行,但我想在 blade 文件中使用 facades 函数无效
Facades in laravel 8 Is perfectly working in controller file but i want to use on facade function in blade file not working
Laravel 8
中的 Facades 在控制器文件中运行良好,但我想在 blade 文件中使用 on facades 函数无效
错误:
Error Call to undefined method App\PaymentGateway\PaymentFacade::process() (View: D:\alpha\resources\views\admin\auth\register_coverage.blade.php)
**在Blade文件中,这是门面函数**
{{ \Payment::process() }} //// this is not working
控制器文件
public function registerStore(Request $request) {
dd(Payment::process()); ///// this is working
}
我想知道这个问题的解决方法。
付款文件
<?php
namespace App\PaymentGateway;
class Payment {
public static function process(){
return "testing";
}
}
PaymentFacade 文件
<?php
namespace App\PaymentGateway\Facades;
class PaymentFacade {
protected static function getFacadeAccessor(){
return 'payment';
}
}
PaymentServiceProvier 文件
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\PaymentGateway\Payment;
class PaymentServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->bind('payment',function(){
return new Payment;
});
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
}
Config/app 文件
'providers' => [ App\Providers\PaymentServiceProvider::class,
],
'aliases' => [ 'Payment'=> App\PaymentGateway\Facades\PaymentFacade::class,
],
您应该扩展基础 Facade class。将 App/PaymentGateway/Facades/PaymentFacade.php 更改为
<?php
namespace App\PaymentGateway\Facades;
use Illuminate\Support\Facades\Facade;
class PaymentFacade extends Facade {
protected static function getFacadeAccessor(){
return 'payment';
}
}
Laravel 8
中的 Facades 在控制器文件中运行良好,但我想在 blade 文件中使用 on facades 函数无效
错误:
Error Call to undefined method App\PaymentGateway\PaymentFacade::process() (View: D:\alpha\resources\views\admin\auth\register_coverage.blade.php)
**在Blade文件中,这是门面函数**
{{ \Payment::process() }} //// this is not working
控制器文件
public function registerStore(Request $request) {
dd(Payment::process()); ///// this is working
}
我想知道这个问题的解决方法。
付款文件
<?php
namespace App\PaymentGateway;
class Payment {
public static function process(){
return "testing";
}
}
PaymentFacade 文件
<?php
namespace App\PaymentGateway\Facades;
class PaymentFacade {
protected static function getFacadeAccessor(){
return 'payment';
}
}
PaymentServiceProvier 文件
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\PaymentGateway\Payment;
class PaymentServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
$this->app->bind('payment',function(){
return new Payment;
});
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
}
Config/app 文件
'providers' => [ App\Providers\PaymentServiceProvider::class,
],
'aliases' => [ 'Payment'=> App\PaymentGateway\Facades\PaymentFacade::class,
],
您应该扩展基础 Facade class。将 App/PaymentGateway/Facades/PaymentFacade.php 更改为
<?php
namespace App\PaymentGateway\Facades;
use Illuminate\Support\Facades\Facade;
class PaymentFacade extends Facade {
protected static function getFacadeAccessor(){
return 'payment';
}
}