Reputation: 1318
I need to get data sent from android device.Those sent data should be stored in my table called 'leave' where there are three fields they are 'id','reason' and 'description'. What i am able to do till now is i have set up my route as:
Route::any('jsontest','JsonController@JsonFunction');
And in my controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
class JsonController extends Controller
{
public function jsonFunction(request $request){
$requestObj=Input::all();
if(count($requestObj) > 0)
{
return response()->json(['success'=>true,'request_param'=>$requestObj]);
}
else
{
return response()->json(['success'=>false,'error'=>'send some data']);
}
}
}
now when I hit this in browser : http://rentma.net/attendance/public/jsontest then this comes:
{"success":false,"error":"send some data"}
which is the message from else part.And when I pass parameters from url like this: http://rentma.net/attendance/public/jsontest?name=suzan then this comes:
{"success":true,"request_param":{"name":"suzan"}}
you can try it also since it is already in server. but what i want is i want datas to be passed from android device and show that data in view. How can I do that? can anyone help?
Upvotes: 0
Views: 302
Reputation:
I think the best is to check laravel events
there was something like Event::listen() for inserting in db check here
once event is triggered, make an ajax call to get the data you need and modify the view to show it
$.ajax({
url: 'test-grab',
data: {token: _token},
success: function(response){
$('body').html(response) // or if it's to a class/id mark the class
}
});
Upvotes: 1