Ahoi,
want to use static methods and public method (of Instance) from a Model.
have a controller :
class Company extends BaseController
{
private $model;
public function __construct(){
$this->model = new CompanyModel();
}
public function index(){
$doSomething = $this->model->doSomething();
$doStatic = CompanyModel::doStatic();
}
}
have a model:
class CompanyModel extends Eloquent
{
private $company;
public function __construct(){
$this->company = null;
}
public function doSomething(){
//code;
}
public static function doStatic(){
//code;
}
}
Is this the way of best practice to work with MVC in Laravel?
Sorry for my bad english
Eloquent models have a magic static call built in to handle dynamic static calls to model methods, so you can still call CompanyModel::doSomething()
and the __callStatic() method within Eloquent will route your request correctly - this means its not necessary to define your model methods as static.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community