Your question is a bit vague but I think you want to reuse the same model for multiple resources in Nova, right?
So in that case, you can create a new resource, point to the same model, but update the indexQuery to fetch the correct results
class HolyMeal extends Resource
{
public static $model = \App\Food::class;
public static function indexQuery(NovaRequest $request, $query): Builder
{
$query = $query->where('type', 'holy_meal');
return parent::indexQuery($request, $query);
}
}
Another solution is creating multiple models and using a global query scope to determine the correct type. You can create multiple models that look at the same table.
in food model i have two columns one is the name and other is type
i have 4 types each type is a resource in nova
and it's work pretty , and i was having index query method as yours
but the problem is when i create Holy meal record , in the db the creation save the type as cuisine not the correct type , so how could i make it save type as the name of resource
Use the Nova Hidden Field package to set an hidden input containing your type value
Create your own custom field which implements a hidden input
Last resort: Use a (nasty) little hack to inject your type in the request. To do so, create a "useless" validation rule on a field that will always be present in your create and update forms :