I created a laravel middleware with this code:
<?php
namespace AppHttpMiddleware;
use Closure;
use IlluminateHttpRequest;
use SymfonyComponentHttpFoundationResponse;
use AppContainersModalsModelsModal;
class ModalsMiddleware
{
/**
* Handle an incoming request.
*
* @param Closure(IlluminateHttpRequest): (SymfonyComponentHttpFoundationResponse) $next
*/
public function handle(Request $request, Closure $next, string $modalNames): Response
{
$modals = explode(',', $modalNames);
foreach ($modals as $modalName) {
$modal = Modal::where('slug', $modalName)->first();
if (!$modal->enabled) {
abort(404);
}
}
return $next($request);
}
}
Then I updated Kernel.php
:
**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array<string, class-string|string>
*/
protected $routeMiddleware = [
...,
'modals' => AppHttpMiddlewareModalsMiddleware::class,
];
And for my route group I added the following: 'middleware' => ['auth:api', 'modals:AModalName']
Then I ran:
php artisan optimize && php artisan config:cache && php artisan cache:clear && php artisan config:clear && composer dump-autoload
And stoped serve then I re-ran the app
However I had this error:
"message": "Target class [modals] does not exist.",
"exception": "Illuminate\Contracts\Container\BindingResolutionException",
How can I fix that?