samedi 29 juin 2019

Why laravel returns class not exist error? However everything seems fine

I created service in the App/Services folder and then I am using it controller.

So in the services folder I have following file

namespace App\Services;
use GuzzleHttp\Client;
class SubscriptionService
{
    private $subUsername    = 'M****************b';
    private $subPassword    = 'V********g';
    private $subSource      = 'o*********k';
    private $subMinisite    = 'a*******m';

    public function pinVerify($request){
        $DataArray = [];
        $client     = new Client();
        $route = 'http://b*******e.com/****/P***y.php';
        $params = [
            'form_params' => [
                'Username'      => $this->subUsername,
                'Password'      => $this->subPassword,
                'userID'        => $request->user_id,​
                'pincode'       => $request->pin_code
            ]
        ];      
        $result = $client->request(​'POST'​, $route, $params);       
        $body = $result->getBody();       
        $bodyContent = $body->getContents();
        if($bodyContent === 1){
            $DataArray['message']   = 'Failed because of system error';
            $DataArray['status']    = 'failed';  
        }else{
            $DataArray['message']   = 'Sorry provided pincode is wrong.';
            $DataArray['status']    = 'failed';  
        } 
        return $DataArray;
    }
}

And then in the controller in am using it in one method as like below

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\SubscriptionService as Subscription;
class XyzController extends Controller
{
    public function verifyPinCode(Subscription $Subscription, Request $request){
        $serviceResponse = $Subscription->pinVerify($request);
        return response()->json($serviceResponse, 200); 
    }
}

But in the result I am getting error Class does not exist, I am not sure where I am doing mistake. Can someone kindly guide me how to fix the issue, would appreciate it.

Thank you

Error

ReflectionException
Class App\Services\SubscriptionService does not exist
Previous exceptions
syntax error, unexpected ''pincode'' (T_CONSTANT_ENCAPSED_STRING)



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Yj5PeS
via IFTTT

Aucun commentaire:

Enregistrer un commentaire