微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

laravel 8 中的外观在控制器文件中完美运行,但我想在刀片文件中使用外观功能不起作用

如何解决laravel 8 中的外观在控制器文件中完美运行,但我想在刀片文件中使用外观功能不起作用

Laravel 8 中的外观在控制器文件中完美运行,但我想在刀片文件中使用外观功能不起作用

错误

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()
{
    //
}
}

配置/应用文件

'providers' => [ App\Providers\PaymentServiceProvider::class,],'aliases' => [ 'Payment'=> App\PaymentGateway\Facades\PaymentFacade::class,

解决方法

您应该扩展基础 Facade 类。将 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';
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。