I'm having an issue "new for me" since i was able to store the data in database but now i can't. I'm passing some fields through ajax and it was working good but now it isn't.
Here's my controller code:
public function update_os(Request $request)
{
$this->validate($request, [
'os' => 'required|max:50'
]);
$user = User::find(Auth::id());
$user->fill([
'os' => $request->os
]);
return response()->json($user);
}
Now this is my ajax code:
$(document).on('submit', '#AjaxFormOs', function (event) {
event.preventDefault();
var os = $('#AjaxFormOs').serializeArray();
$.ajax({
method: 'post',
url: userUrl + 'updateos',
data: os,
_token: token,
dataType: 'json'
})
.done(function (operative) {
toastr.info("Your new OS is: " + operative.os + "", 'You have been updated your OS info.', {timeOut: 5000});
$('#os-cancel').addClass('hide');
$('#os').addClass('hide');
$('#user-os').removeClass('hide');
$('.user-info-content').find('#user-os').html(operative.os);
$('#os-edit').removeClass('hide');
});
});
This is the route:
Route::post('/{username}/updateos', 'Account\ProfileController@update_os');
This is the form:
<form id="AjaxFormOs">
{{ csrf_field() }}
<ul class="list-inline p-r-10 user-info-details-form">
<li><strong>OS</strong></li>
<li class="m-l-20 p-b-10" id="user-os">{{ $user->os }}</li>
<li>
<input id="os" type="text" class="form-control hide user-input-field" name="os" value="{{ $user->os }}" autofocus>
<button type="submit" class="hide"></button>
</li>
<li class="pull-right"><a href="#" id="os-edit">Edit</a></li>
<li class="pull-right"><a class="hide" href="#" id="os-cancel">Cancel</a></li>
</ul>
</form>
This is the response "from google chrome developer tools"
Request URL: http://centralgeek.test/9/updateos
Status Code: 200 OK
{id: 9, name: "José", last_name: "Martínez", username: "josem",
gender: "Hombre", os: "Ubuntu",…}
about: null
background: "def-background.jpg"
city: "Curicó"
country: "Venezuela"
created_at: "2018-10-09 00:32:45"
deleted_at: null
email: "[email protected]"
gender: "Hombre"
id: 9
job_title: "¿A qué te dedicas?."
last_login_at: "2018-10-09 00:32:45"
last_login_ip: "127.0.0.1"
last_name: "Martínez"
name: "José"
os: "Ubuntu"
phone_model: null
profilepic: "default.png"
twitter: null
twitter_link: null
updated_at: "2018-10-09 01:21:41"
user_agent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36"
username: "josem"
As you can see there the os data i've passed is "ubuntu" but once i refresh de window that info disappear.. Is not storing it on database, but it was working before. So what's happening?.
Thanks in advance.