Access current Eloquent model in a backend form
5
Sometimes you need to access attributes or methods of the current model in a backend form (let's say in a custom partial). You can access the model via the vars
property:
$this->vars['formModel'];
Of course you have also access to all the model's properties and methods:
$this->vars['formModel']->id;
$this->vars['formModel']->title;
$this->vars['formModel']->customMethod();
Exactly as Daniel says. Additionally, $this->vars array is defined at the controller level and its content can be used directly within partials, so:
will also work, you can add any custom values to this array in eg. controller's index method and use it directly as a variable in backend partials.
Also you can use a simplier way:
$model; $model->id; $model->title; $model->customMethod();