First of all, i have read and tried what's on this post : Laravel change input value
My goal is to change some inputs' values on page load, but i am doing wrong somewhere.
i.e. I have some inputs filled by user lately, now i want them to edit these fields. So i need to pull some data from database and insert these into my inputs.
navTabs.js
$(document).ready(function(){
$('#myTab a').on(function (e) {
e.preventDefault();
$(this).tab('show');
},myOnLoadFunction());
}
function myOnLoadFunction(){
$.post('myRoute');
}
Routes.php :
Route::post('myRoute', array(
'uses' => 'MyController@myMethod',
'as' => 'myRoute'
));
MyController.php
public function myMethod(){
Input::merge(array('myInputName' => 'theValueFromDatabase'));
}
So, i am making a mistake somewhere, but i couldn't find it out.
Everything works fine on test until myMethod i can get responses.
Am I using merge method wrong ?
Thanks in advance.
UPDATE
MyController.php
public function myMethod(){
Input::merge(array('myInputName' => 'theValueFromDatabase'));
//i have nearly 15 inputs here, assigning each of them one by one.
$allVariablesWithNewInput = \Input::all();
return Response::json($allVariablesWithNewInput);
}
Now this value is being returned to navTabs.js
function myOnLoadFunction(){
$.post('myRoute', function(data){
document.getElementById('myFieldID').value = data['myInputName'];
//and assign 15 more inputs here to see values on html elements.
});
}
First of all, thank you for your patience. We figured out to find a solution to my problem with this way. But i am not satisfied with this solution. I'm going to have to write a lot of code here. Is there any way to reduce repetition ? Do you offer an algorithm or something else ?
Thank you.