I'm using Laravel 7.x and want to create a new search index for Algolia (with Laravel Scout).
As I've come to learn I can achieve this with the command "php artisan scout:import"
. Laravel Scout as well as Passport are installed and I remember this used to work earlier.
Unfortuantely now, a few months later it doesn't work anymore, surely due to my fault changeing smth. in Auth or the like.
If I send "php artisan scout:import"
I get the following error:
ErrorException
Declaration of
App\Http\Middleware\Authenticate::authenticate(array $guards)
should be compatible with
Illuminate\Auth\Middleware\Authenticate::authenticate($request, array $guards)
at D:\laragon\www\myproject\app\Http\Middleware\Authenticate.php:55
51| * @return void
52| *
53| * @throws \Illuminate\Auth\AuthenticationException
54| */
> 55| protected function authenticate(array $guards)
56| {
57|
58| if (empty($guards)) {
59| return $this->auth->authenticate();
1 D:\laragon\www\myproject\app\Http\Middleware\Authenticate.php:10
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Declaration of App\Http\Middleware\Authenticate::authenticate(array $guards) should be compatible with Illuminate\Auth\Middleware\Authenticate::authenticate($request, array $guards)",
"D:\laragon\www\myproject\app\Http\Middleware\Authenticate.php", [Object(Algolia\ScoutExtended\Console\Commands\ReImportCommand), Object(Symfony\Component\Finder\Finder), Object(Symfony\Component\Finder\SplFileInfo)])
2 D:\laragon\www\myproject\vendor\algolia\scout-extended\src\Helpers\SearchableFinder.php:113
require_once("D:\laragon\www\myproject\app\Http\Middleware\Authenticate.php")
I'd like to find the root of the issue but I don't understand the error:
Declaration of
App\Http\Middleware\Authenticate::authenticate(array $guards)
should be compatible with
Illuminate\Auth\Middleware\Authenticate::authenticate($request, array $guards)
Any hints/tipps where to start looking are very welcome.
UPDATE: Here's the method in Authenticate.php that might be the issue:
protected function authenticate(array $guards)
{
if (empty($guards)) {
return $this->auth->authenticate();
}
foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
return $this->auth->shouldUse($guard);
}else{
return null;
}
}
throw new AuthenticationException('Unauthenticated.', $guards);
}
the entire Authenticate.php is:
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Contracts\Auth\Factory as Auth;
class Authenticate extends Middleware
{
/**
* The authentication factory instance.
*
* @var \Illuminate\Contracts\Auth\Factory
*/
protected $auth;
/**
* Create a new middleware instance.
*
* @param \Illuminate\Contracts\Auth\Factory $auth
* @return void
*/
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string[] ...$guards
* @return mixed
*
* @throws \Illuminate\Auth\AuthenticationException
*/
public function handle($request, Closure $next, ...$guards)
{
$this->authenticate($guards);
return $next($request);
}
/**
* Determine if the user is logged in to any of the given guards.
*
* @param array $guards
* @return void
*
* @throws \Illuminate\Auth\AuthenticationException
*/
protected function authenticate(array $guards)
{
if (empty($guards)) {
return $this->auth->authenticate();
}
foreach ($guards as $guard) {
if ($this->auth->guard($guard)->check()) {
return $this->auth->shouldUse($guard);
}else{
return null;
}
}
throw new AuthenticationException('Unauthenticated.', $guards);
}
}