I have an ajax function whose job is to append a row in a datatable whenever I store. The problem is when it appends, obviously, it appends what was inputted. But I want that all foreign keys to correspond to it's name.
for example..
a user's job id is 5... so in ajax i want to append that $user->job->name
can I call a model in ajax?
This is how my ajax looks like btw..
$.ajax({
type: 'POST',
url: '{{ ('/users') }}',
data: {
'_token': $('input[name=_token]').val(),
'name': $('input[name=user_name]').val(),
'email': $('input[name=user_email]').val(),
'password': $('input[name=user_password]').val(),
'role_id': $('#user_role option:selected').val(),
'team_id': $('#user_team option:selected').val()
}}).done(function( data ) {
//add rows in modal
$('#userTable').append("<tr class='item" + data.id + "'><td align='center'><input type='checkbox' class='i-checks' name='input[]' value='"+data.name+"'> </td><td>" + data.name + "</td><td>" + data.email + "</td><td>" + data.role_id + "</td><td>" + data.team_id + "</td><td>" + data.team_id + "</td><td><a data-toggle='modal' href='#modal-edit-" + data.id +"'><i class='fa fa-pencil'></i> Edit</a></td><td><button class='edit-modal btn btn-info' id='editUser' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-edit'></span> Edit</button></td></tr>");
//clear the modal
$("#modal-add-user").find("input,select").val('').end();
});