Reputation: 1346
Facades in Laravel 8
Are perfectly working in the controller file but I want to use on facade function in the blade file not working
error:
Error Call to undefined method App\PaymentGateway\PaymentFacade::process() (View: D:\alpha\resources\views\admin\auth\register_coverage.blade.php)
**On Blade file, this is facade function **
{{ \Payment::process() }} //// this is not working
Controller file
public function registerStore(Request $request) {
dd(Payment::process()); ///// this is working
}
I want to know the solution to this problem.
Payment File
<?php
namespace App\PaymentGateway;
class Payment {
public static function process(){
return "testing";
}
}
PaymentFacade File
<?php
namespace App\PaymentGateway\Facades;
class PaymentFacade {
protected static function getFacadeAccessor(){
return 'payment';
}
}
PaymentServiceProvier File
<?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 file
'providers' => [ App\Providers\PaymentServiceProvider::class,
],
'aliases' => [ 'Payment'=> App\PaymentGateway\Facades\PaymentFacade::class,
],
Upvotes: 0
Views: 705
Reputation: 278
You should extend the base Facade class. Change App/PaymentGateway/Facades/PaymentFacade.php to
<?php
namespace App\PaymentGateway\Facades;
use Illuminate\Support\Facades\Facade;
class PaymentFacade extends Facade {
protected static function getFacadeAccessor(){
return 'payment';
}
}
Upvotes: 1