我在我的网站上使用spatie/laravel-searchable。它在此功能中运行良好:
public function index(Request $request)
{
$results = (new Search())
->registerModel(Product::class, 'name', 'price','barcode')
->registerModel(Category::class, 'name')
->registerModel(Catalog::class, 'name')
->registerModel(Color::class, 'fatitle','entitle')
->search($request->input('query'));
return response()->json($results);
}
但在某些方面(如:cu006),我有这个错误:
Argument 2 passed to Spatie\Searchable\SearchResult::__construct() must be of the type string, null given
vendor/spatie/laravel-searchable/src/SearchResult.php:19
public function __construct(Searchable $searchable, string $title, ?string $url = null)