Custom middleware

Published

I’m trying to create custom middleware but i’m getting this error.
‘Target class [AppHttpMiddlewareOrderApproved] does not exist.’
Don’t know where he does not get OrderApproved.

middleware

<?php

namespace AppHttpMiddleware;

use AppModelsOrder;
use Closure;
use IlluminateSupportFacadesAuth;

class OrderApproved
{
    /**
     * Handle an incoming request.
     *
     * @param  IlluminateHttpRequest  $request
     * @param  Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = Auth::user();

        $BuyedQuery = Order::where('user_id', $user->id)->where('status', 'successful')->get();
        if ($BuyedQuery) {
            return $next($request);
        }
        return response()->json('Your order is not approved');

    }
}
?>

In kernel i added in protected $routeMiddleware

'orderApproved' => AppHttpMiddlewareOrderApproved::class,

route


Route::middleware([OrderApproved::class])->group(function(){

Route::get('/full-course/{slug}', [WebController::class, 'afterBuy'])->name('watchCoursePage');

});

Source: Laravel

Published
Categorised as laravel, php Tagged ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq