Level 1
i got the answer for this.. not well documented on the documentation
Resource
public function fields(Request $request)
{
return [
BelongsTo::make('Formula')
->searchable()
->rules('required'),
BelongsTo::make('Tank')
->rules('required'),
];
}
Model
public function formula() : BelongsTo
{
return $this->belongsTo(Formula::class);
}
public function tank()
{
return $this->belongsTo(Tank::class);
}
to filter the relation must add this code on the Resource
public static function relatableFormulas(NovaRequest $request, $query)
{
return $query->where('active', true);
}
public static function relatableTanks(NovaRequest $request, $query)
{
return $query->where('active', true);
}
if the name for the field is Something then the function name must be relatableSomethings
7 likes