You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.
Same use case. Looking into this, this field has a callback that passes a default "search" parameter into the field and fires the search function when the field is loaded. This, for the most part, just keeps the default Nova implementation of the BelongsTo field (it does however, overwrite the field, if the field is for whatever reason updated), and just fires its search.
Nova, by itself, doesn't offer pagination on the associatable endpoint. It calls the relatableQuery, as @freshway has pointed out.
The reason that works is because the search parameter wont be null when searching from Laravel Nova. It only performs the search once the user types something in. If its blank, we can assume its coming from the prepopulate call.
Because of this, you can actually apply that to all resources by overriding it in your default Resource class.
Put this in Resource.php:
/**
* Build a "relatable" query for the given resource.
*
* This query determines which instances of the model may be attached to other resources.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function relatableQuery(NovaRequest $request, $query)
{
if( !$request->filled('search')){
return parent::relatableQuery($request, $query)->limit(25);
}
return parent::relatableQuery($request, $query);
}
is there any way to add limit this query ? i wanna limit prepopulate to 10 record. Thanks.
The text was updated successfully, but these errors were encountered: