由于Laravel Nova全局搜索会忽略策略,因此我想覆盖它的控制器。某种程度上,这不起作用,全局搜索默认为Laravel\Nova\Http\Controllers\SearchController
。
我到目前为止所拥有的:
app/config.php
//..
'providers' => [
//..
App\Providers\RouteServiceProvider::class,
App\Providers\NovaServiceProvider::class,
//..
],
(请注意提供者的顺序)
routes/web.php
//..
Route::get('nova-api/search', 'SearchController@index');
app/Http/Controllers/SearchController.php
namespace App\Http\Controllers;
use Laravel\Nova\Nova;
use Laravel\Nova\GlobalSearch;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Http\Controllers\SearchController as NovaSearchController;
class SearchController extends NovaSearchController
{
/**
* Get the global search results for the given query.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return \Illuminate\Http\Response
*/
public function index(NovaRequest $request)
{
return (new GlobalSearch(
$request, Nova::globallySearchableResources($request)
))->get();
}
}
版本
这不起作用。路线nova-api/search
仍指向Laravel\Nova\Http\Controllers\SearchController
。我在做什么错了?
答案 0 :(得分:2)
我遇到了同样的问题,这就是我的解决方法。
在AppServiceProvider.php中,将以下代码添加到引导方法中:
$this->app->bind(
NovaController::class,
YourController::class
);