I want to retrieve the data values in a controller function which I am sending through ajax, but unable to achieve it.
Here is my ajax code -
var postArg = {startDate:localStorage.getItem('startDate'), endDate:localStorage.getItem('endDate'), startTime:localStorage.getItem('startTime'), endTime:localStorage.getItem('endTime')}
$http.post('checkvehicleavailability', angular.toJson(postArg), {
withCredentials: true,
headers: {'Content-Type': "application/x-www-form-urlencoded" }
}).success(function(data, status) {
console.log(data);
});
and here is my laravel controller function -
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Routing\Controller;
use App\Http\Controllers\Input;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Support\Facades\Validator;
class VehicleController extends Controller
{
public function vehicleAvailability(){
$request = new Request();
$data = $request->all();
var_dump($data);
die();
}
}
Here is my route -
Route::post('checkvehicleavailability','VehicleController@vehicleAvailability');
When I check with postman, then I get this response-
array(0) { }
I have seen many stackoverflow links but none of them worked out for me. Please someone help me to retrieve the data.