header('X-API-TOKEN') && ($user = CompanyToken::whereRaw("BINARY `token`= ?",[$request->header('X-API-TOKEN')])->first()->user ) ) { //$user->with('company'); auth()->login($user); } else { $error['error'] = ['message' => 'Invalid token']; return response()->json(json_encode($error, JSON_PRETTY_PRINT) ,403); } return $next($request); } }