I want to integrate the const data variable into the php file externally. What code does it do? I am changing the data on my php page to json format, but how do I pull it into the javascript page?
User.js File:
const data = {users: [
{
id: 1,
fullName: 'Galen Slixby',
company: 'Yotz PVT LTD',
role: 'editor',
username: 'gslixby0',
country: 'El Salvador',
contact: '(479) 232-9151',
email: '[email protected]',
currentPlan: 'enterprise',
status: 'inactive',
avatar: '',
},
],
}
User.php file:
$response = []; $response['users']=[]; foreach($firmalar as $firma){ $response['data'][] = [
"avatar"=>"",
'id'=> $firma['id'],
'responsive_id' => '',
'full_name'=> $firma['firma_adi'],
'email'=> $firma['firma_mail'],
'role'=> $firma['firma_sektor'],
'current_plan'=> $firma['firma_telefon'],
'status'=> $firma['firma_tehlike']
]; } echo json_encode($response);
2
Answers
response()->json($result); is the solution!
IIUC the structure you’re aiming for require to map it in PHP.
So you have an object with one element
users
and value – array of objects (potentially users). Keeping that in mind you should have same thing in PHP before encoding.Please follow json_encode documentation for more details on usage.
Cheers!