01-15-2021, 10:06 AM
Documentation says
In Services.php i have 6 such methods as
I have to write in every model
The services provided are global. Can be run in the controller and model. Is there a better practice? In fact, it needs global methods. Something like a helper but from App \ Libraries
Quote:It is recommended to only create services within controllers. Other files, like models and libraries should have the dependencies either passed into the constructor or through a setter method.
In Services.php i have 6 such methods as
PHP Code:
public static function permissions($getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('permissions');
}
return new \App\Libraries\Permissions();
}
I have to write in every model
PHP Code:
class SomeModel extends Model {
protected $permissions;
protected $limiters;
protected $vertical;
protected $abs_field;
protected $forater;
protected $statistic;
public function __construct(
\App\Libraries\Permissions &$permissions,
\App\Libraries\Limiters &$limiters,
\App\Libraries\Vertical &$vertical,
\App\Libraries\Abs_field &$abs_field,
\App\Libraries\Forater &$forater,
\App\Libraries\Statistic &$statistic )
{
$this->$permissions =& $permissions;
$this->$limiters =& $limiters;
$this->$vertical =& $vertical;
$this->$abs_field =& $abs_field;
$this->$forater =& $forater;
$this->$statistic =& $statistic;
}