jeudi 2 août 2018

Facades: Non-static method should not be called statically

I am created a class and Facade like so:

Invoice.php (Facades/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';
    }
}
?>

InvoiceFacadesServiceProviders.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;
      });
   }
}
?>

And finally the class itself:

<?php


namespace App\Invoice;

class Invoice
{
    public function testfunc()
    {
        return "This is a test";
    }
}
?>

In a controller I try to test it by using the class like so:

use App\Invoice\Invoice;

And calling the testfunc method:

dd(Invoice::testfunc());

In the app.php I have added the following (providers): App\Providers\InvoiceFacadesServiceProvider::class, and (aliases): 'invoice' => App\Facades\Invoice::class,

But I only get:

Non-static method App\Invoice\Invoice::testfunc() should not be called statically.

I also notice that the getFacadeAccessor() method never gets fired since it does not hit the dd I have put there.

What am I missing here?

Thanks for any help and guidance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire