-
Description:Relatable attribute methods are not working, I need to filter the belongsTo options, because I have a field called "parent" with self-reference and when I edit a resource, I don't want it to appear as an option. Official doc: https://nova.laravel.com/docs/4.0/resources/authorization.html#relatable-filtering I have the following resource classes and none of the relatableParent or relatableParents methods are called: Resource: // Fields
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),
BelongsTo::make('Parent', 'parent', static::class)
->sortable()
->nullable()
->withoutTrashed(),
Text::make('Name')
->sortable()
->rules('required'),
Select::make('Condition')
->sortable()
->rules(['required', 'in:and,or'])
->displayUsingLabels()
->options(fn () => [
['value' => 'and', 'label' => 'And'],
['value' => 'or', 'label' => 'Or'],
]),
Select::make('Operator')
->sortable()
->rules(['required', 'in:eq,ne,in'])
->displayUsingLabels()
->options(fn () => [
['value' => 'eq', 'label' => 'Equals'],
['value' => 'ne', 'label' => 'Not Equals'],
['value' => 'in', 'label' => 'In'],
]),
Text::make('Field')
->sortable()
->rules('required'),
Text::make('Value')
->sortable()
->rules('required'),
];
}
// Relatable attribute methods
public static function relatableParent(NovaRequest $request, $query)
{
$resourceId = $request->route('resourceId');
return $query->whereNotIn('id', [$resourceId]);
}
public static function relatableParents(NovaRequest $request, $query)
{
$resourceId = $request->route('resourceId');
return $query->whereNotIn('id', [$resourceId]);
}Model: <?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
class QueryBuilder extends Model
{
use SoftDeletes;
protected $table = 'query_builder';
protected $fillable = [
'parent_id',
'name',
'condition',
'operator',
'value',
];
public function parent(): BelongsTo
{
return $this->belongsTo(
static::class,
'parent_id',
'id',
);
}
}Even with the methods configured according to the documentation, the method is not called and the "Filter 3" record is still available for selection, as shown in the image below: Detailed steps to reproduce the issue on a fresh Nova installation:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 13 replies
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
The problem is still the same, relatable attribute methods aren't called. |
Beta Was this translation helpful? Give feedback.


It should have been
relatableQueryBuilders()