Level 1
Try to call json_encode on $requestData
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everybody ! I need help on something that I can't understand...
Well, I make an ajax request in a blade template to get data about a specific ID model. This is my code :
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$('.table-responsive').on('click','.change-state-btn', function(e) {
e.preventDefault();
$.ajax({
url: "{{ route('get.xhr.request')}}",
method: 'get',
data: {
id: $(this).data('request')
},
dataType: "json",
success: function(result){
console.log(result.result);
},
done: function(result){
console.log(result.result);
},
error: function(error) {
console.log(error);
}
});
});
My route :
Route::get('/intranet/request', 'Dashboard\RequestController@getRequestForStateEdit')->name('get.xhr.request');
And my controller and repository :
// Repository
public function getRequestForStateEdit($id) {
return $this->model->where('id', $id)->with('joinFiles')->get();
}
// Controller
public function getRequestForStateEdit(Request $request) {
$id = $request->input('q');
$requestData = $this->requestRepository->getRequestForStateEdit($id);
return response()->json(['result' => $requestData]);
}
If I dd($requestData) on my controller I've the good result :

But my ajax request return alway a empty json :

Am I missing something? How can I fix it? Thank you in advance for your help!
Please or to participate in this conversation.