Suppose this is your category model
class Category extends Model
{
use HasFactory, Searchable;
public function toSearchableArray(): array
{
return ['name' => $this->type];
}
public function parent()
{
return $this->belongsTo(Category::class, 'parent_category_id');
}
}
Then you can load relations by the following way
$categories = tap(Category::search($request->key)->paginate($request->perPage ?? 10), function ($categories) {
return $categories->load('parent');
});