TShrestha
TShrestha

Reputation: 1318

Getting data from Android device in laravel

I am trying to get data from android in server in laravel. What I did till now is : here in my route:

    Route::any('jsondata','JsonController@jsonFunction');

And in my controller:

      public function jsonFunction()
 {
    $jsonPostedData = Input::all();
    return response(['jsonobjtest'=>$jsonPostedData]);
}

}

What it gives in browser is:

    {"jsonobjtest":[]}

Actually i want to do is i want to send a success message to android device when it sends data. And get data here in server.

Upvotes: 0

Views: 1429

Answers (3)

santosh
santosh

Reputation: 381

You can check whether

$jsonPostedData = Input::all();

input contain data or not by by simply

die and dumping $jsonPostedData variable

example dd($jsonPostedData);

Upvotes: 1

HItesh Tank
HItesh Tank

Reputation: 686

You can try following code

  public function jsonFunction(){
    $requestObj=Input::all();
return response()->json(['success'=>true,'request_param'=>$requestObj]);
    }

Upvotes: 1

Vikash
Vikash

Reputation: 3551

You can write like this

In your Controller

public function jsonFunction()
{
  $jsonPostedData = Input::all();

   // do something with your data insert or update or anything 

  if(count($jsonPostedData) > 0) // here you might write any of your condition.
  {
    return response()->json(['success'=>true]);
  }
  return response()->json(['success'=>false,'error'=>'your error message']);
}

Upvotes: 1

Related Questions