The error message "array_key_first(): Argument #1 ($array) must be of type array, int given" indicates that the argument passed to the array_key_first() function is not an array, but an integer.
In your code, the error is likely occurring in the handle() method of your middleware. Specifically, the line abort('403', 'Acción prohibida, usted no tiene permiso a esta parte del sistema'); is causing the issue.
To fix this error, you need to ensure that the first argument passed to the abort() function is an array, not an integer. The first argument of the abort() function should be the HTTP status code, followed by an array of headers.
Here's the corrected code for your middleware:
public function handle(Request $request, Closure $next, ...$roles): Response
{
if (!in_array($request->user()->role, $roles)) {
abort(403, ['Acción prohibida, usted no tiene permiso a esta parte del sistema']);
// return redirect('/');
} else {
// dd($request);
return $next($request);
}
}
By passing the HTTP status code as an integer (403) and the error message as an array (['Acción prohibida, usted no tiene permiso a esta parte del sistema']), the error should be resolved.
Remember to clear your cache after making this change by running the following command:
php artisan cache:clear
This should fix the "array_key_first()" error in your middleware.