Get data from controller to controller ın laravel

Viewed 46

I'm trying to write an api with Laravel and ı am new to writing api. I want this api to send data to the mock api I wrote and return the result in response. I looked through the Laravel documentation but couldn't find anything that works for me. By sending data to AndroidController by the PurchaseController, I want the data to be returned to the PurchaseController after the controller runs.

The directory structure is as follows: +api -PurchaseController +android -AndroidController

###AndroidController###

public static function check(Request $request)
    {
        $data = AndroidModel::where('receipt', '=', $request->receipt)->get();
        $expireDate = date('Y-m-d H:i:s T', (strtotime($data[0]->expireDate) - 21600));
        $validation = $data[0]->receipt . $data[0]->validation;


        if (strlen($validation) > 2) {
            if ($data[0]->validation == 1) {

                $response =
                    [
                        'status' => 'true',
                        'code' => 200,
                        'expireDate' => $expireDate
                    ];
                return response()->json($response);
            } else {
                $response =
                    [
                        'status' => 'false',
                        'code' => 401,
                    ];
                return response()->json($response, 401);
            }
        } else {
            $response =
                [
                    'status' => 'false',
                    'code' => 401,
                    'message' => 'Hatalı Kod!'
                ];
            return response()->json($response, 400);
        }

    }

###PurchaseController###

 public function purchase(Request $request): \Illuminate\Http\JsonResponse
    {

        $expireDate = date('Y-m-d H:i:s T', (strtotime($this->date) - 21600));

        $receipt = $request->receipt;
        $register = RegisterModel::where('clientToken', '=', $request->clientToken)->get();
        $uid = $register[0]->uid;
        $os = $register[0]->os;

        $applications = ApplicationModel::where('uid', '=', $uid)->get();
        $appId = $applications[0]->appId;

        $purchaseId = $uid . $appId;


        //OS = Android
        if ($os == 1) {
            $purchase =
                [
                    'purchaseId' => $purchaseId,
                    'expireDate' => $expireDate,
                ];
            PurchaseModel::create($purchase);

            return response()->json([
                'uid' => $uid,
                'os' => $os,
                'appId' => $appId,
                'expireDate' => $expireDate,
            ], 200);


            //OS = iOS
        } else {

            $purchase =
                [
                    'purchaseId' => $purchaseId,
                    'expireDate' => $expireDate,
                ];
            PurchaseModel::create($purchase);

            return response()->json([
                'uid' => $uid,
                'os' => $os,
                'appId' => $appId,
                'expireDate' => $expireDate,
            ], 200);
        }
    }

expireDate value must come from AndroidController

0 Answers
Related