Answer the question
In order to leave comments, you need to log in
Why does Laravel complain about the lack of constants?
New to Laravel.
There is a class in which I am supposed to have business logic:
<?php
namespace App\Services;
class FinanceService
{
const REVENUE = 'plus';
const EXPENSES = 'minus';
public function get()
{
// что-то делаем
}
$this->app->singleton('Finance', function (){
return new FinanceService();
});
<?php
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Finance extends Facade {
protected static function getFacadeAccessor() {
return 'Finance';
}
}
'Finance' => App\Facades\Finance::class,
Finance::get()
, then everything works. But if you try to get a constant Finance::REVENUE
, then the error is:Undefined class constant 'REVENUE'
Answer the question
In order to leave comments, you need to log in
Finance::get()
it's simple resolve(Finance::class)->get()
, so your constants won't work like that - they're constants.
Use DI instead of facades, and put your constants in a separate enum FinanceOperationType
or similar.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question