lundi 8 mars 2021

Target class [UserByToken] does not exist

Here is my middleware

<?php

namespace App\Http\Middleware;

use App\Http\Controllers\Admin\Auth\AuthController;
use Closure;
use Illuminate\Http\Request;

class UserByToken
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        // echo 'dfdf';
        if ($request->username) {
            return $next($request);
        }

        $data['message'] = "User is Not Logged in!";
        $token = $request->token;
        if (!$token) {
            $data['success'] = 0;
            return response()->json($data);
        }


        $user_detail = new AuthController;
        $user = $user_detail->user_obj_by_token($token, false, '');

        if (!$user) {
            $data['success'] = 0;
            return response()->json($data);
        }

        \Session::put('user', $user);
        \Session::save();

        return $next($request);
    }
}

I added this in kerenal.php, in web array \App\Http\Middleware\UserByToken::class,

Now I am getting the error "Target class [UserByToken] does not exist."

When I add dd($user) in middleware just before return $next($request);, it print and exit there. So I think UserByToken is accessible. But when I remove that line, got this error.

Can anyone please help me with this?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire