--level used: 5Larastan detects false positives in Nova resources.
For example: when I access $this->event, on an Audit resource, Nova actually accesses event on the Audit model.
namespace App\Nova;
/**
* Defines an audit for Nova.
*/
class Audit extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \OwenIt\Auditing\Models\Audit::class;
/**
* Get the value that should be displayed to represent the resource.
*
* @return string
*/
public function title()
{
return $this->event . ' - ' . $this->auditable;
}
}
Just ran into this when trying Larastan for the first time.
Since the main interface for this app is Laravel Nova, the majority of the issues reported by Larastan are actually this false-positive. At the moment, I suppose I'll need to exclude those files.
trying Larastan for the first time.
Very nice!
I'll need to exclude those files.
You may also contribute some code.
You can add @mixin <ModelClass> to the docblock for the Nova resource class.
It still does not work for me:
/**
* @mixin \App\CourseEdition
*/
class CourseEdition extends Resource
{
public function title()
{
return $this->courseTitle;
}
courseTitle is a custom accessor that uses getCourseTitleAttribute on CourseEdition model:
public function getCourseTitleAttribute()
{
return $this->course->title;
}
That should work - yes. The mixing instruction should send the model to the pipes of Larastan no?
Maybe could custom accessor be the problem? When I will be back i will try with a standard property.
We don't support custom getters yet. @alberto-bottarini you can create a new issue for that.
For what it's worth, I had this same problem, and adding @mixin wasn't the solution here either since attributes and relations are all magical in Laravel.
But I noticed that the callbacks get two parameters, a NovaRequest and the model. An undocumented feature, I guess, but this would circumvent having to use $this in that context.
Example:
Text::make('title')
->showOnUpdating(function (NovaRequest $request, MyModel $model) {
// avoid $this by using $model
return $model->has_title;
})
Most helpful comment
We don't support custom getters yet. @alberto-bottarini you can create a new issue for that.