3

Facade (この場合はシングルトン) があり、次を使用して登録しますServiceProvider

サービスプロバイダー

use App;

class FacilityServiceProvider extends ServiceProvider 
{

    public function register()
    {  
        $this->app->singleton('Facility', function(){
            return new Facility();
        });

        // Shortcut so developers don't need to add an Alias in app/config/app.php
        $this->app->booting(function()
        {
            $loader = \Illuminate\Foundation\AliasLoader::getInstance();
            $loader->alias('Facility', 'CLG\Facility\Facades\FacilityFacade');
        });
    }
}

ファサード

use Illuminate\Support\Facades\Facade;

class FacilityFacade extends Facade {

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor() { return 'Facility'; }
}

今、私は自分のFacilityクラス内に静的変数を持ちたいと思っています:

ファシリティ.php

class Facility
{
    public static $MODEL_NOT_FOUND = '-1';

    public function __construct() { ... }
}

しかし、 を使用するFacility::$MODEL_NOT_FOUNDと、 が得られAccess to undeclared static propertyます。

私は何を間違っていますか?

4

1 に答える 1