Because Laravel Nova global search ignores policies, i want to override it's controller. Somehow this doesn't work and the global search defaults to Laravel\Nova\Http\Controllers\SearchController.
What i have so far:
app/config.php
//..
'providers' => [
//..
App\Providers\RouteServiceProvider::class,
App\Providers\NovaServiceProvider::class,
//..
],
(please note the order of the providers)
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();
}
}
Versions
This does not work. The route nova-api/search still points to Laravel\Nova\Http\Controllers\SearchController. What am i doing wrong?
I had the same problem, here's how I solved it.
In AppServiceProvider.php added the following code to the boot method:
$this->app->bind(
NovaController::class,
YourController::class
);
Here's the description of how it works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With