vendredi 26 janvier 2018

How to catch JSON object in controller Laravel

I have created a login api in which i send input value as an JSON object,but the problem is that it doesn't capture any input data. My controller function is something like this

public function login(Request $request){

    //I tried to check if i am receiving input here or not         
    if($request->input('provider')=='web'){
        //Do something
    }else{
        //Return error message
    }
}

But the problem is it seems like i cant retrive the JSON Input values

I am testing this with postman with the following parameter in header

Content-Type: application/json,
Accept:application/json

I followed the Laravel documentation https://laravel.com/docs/5.5/requests and tried to check with $data= $request->input('provider'); if i am getting any response or not but i still the same no response.

I also tried with the following

$data= $request->json()->all(); ///Getting Null
$data= json_decode($request->getContent()); ///Getting Null

I found an article which is similer problem as this on laracast https://laracasts.com/discuss/channels/laravel/how-to-validate-json-input-using-requests But those solution also didnt work for me. Maybe because those are outdate.

So can anyone please help me out how can i retrive JSON input data in the controller to do further actions ?



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

Aucun commentaire:

Enregistrer un commentaire