Passing Multiple Value For PHP API Function

rajrathod :

I am new in PHP and working to modify one API. Its built with Laravel Framework. I have API function like below in my controller.

public function DeleteOneMail(Request $request)
{
    $uid = $request->uid;

    if (\Request::is('api/*')) {
        if ($request->has('key')) {
            if (in_array($request->input('key'), explode(',', env('API_KEY')))) {
                if ($uid == '') {
                    return response()->make('Please Enter UID', 401);
                } else {
                    $client = Client::account('default');
                    $client->connect();
                    $inbox = $client->getFolder('INBOX');
                    $message = $inbox->getMessage($uid);
                    if ($message) {
                        return response(['success' => 1], 200);
                    } else {
                        return response(['success' => 0, 'message' => 'No Data Found'], 200); 
                    }
                }
            } else {
                return response()->make('Unauthorized Access. Please enter correct API Key', 401);
            }
        } else {
            return response()->make('Unauthorized Access. Please enter correct API Key', 401);
        }
    }
}

I am calling API like below

https://example.com/api/delete-one-mail?key=2221212&uid=214

Its working fine without any issue. Now I want pass multiple uid with request and so I can process that uid one by one with my api function. I am not getting idea how I can pass arrary and process it. Let me know if any expert can help me for solve my puzzle. Thanks!

Sébastien R :

Your can pass an array like this

https://example.com/api/delete-one-mail?key=2221212&uid[]=214&uid[]=111&uid[]=222

$request->uid should be an array but you can make sure (if anyone use the old url with ony one uid) by doing

$uids = Arr::wrap($request->uid);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=198932&siteId=1