Just quick example:
<script>
$(function () {
$("#postjq").click(function (event)
{
event.preventDefault();
var $post = {};
$post.petid = $('#petid').val();
$post.species = $('#species').val();
$post.ocheck = ($("#ocheck").prop("checked") == true ? '1' : '0');
$post._token = document.getElementsByName("_token")[0].value
$post._method = document.getElementsByName("_method")[0].value
alert($post.species);
$.ajax({
//url: 'http://localhost/laravel60/pet/petupdate',
url: '<?= DIR . "pet/petupdate" ?>',
type: 'PUT',
data: $post,
cache: false,
success: function (data) {
alert('Your data updated');
return data;
},
error: function (data, ajaxOptions, thrownError) {
var status = data.status;
alert(status);
if (data.status === 422) {
$.each(data.responseJSON.errors, function (key, value) {
$('#msg').append('<div>' + value + '</div>');
});
}
if (status === 403 || status === 500) {
$('#msg').text("Not Auth");
}
//window.location.href = '<?//= DIR . "indexbl" ?>';
}
});
});
});
</script>
controller
public function petUpdate(Request $request)
{
if (!ChkAuth::chkRole('user')) { // ignore custom rbac
abort(403);
}
$request->validate([
'species' => 'required'
]);
$petid = $request->input('petid');
$species = $request->input('species');
//$ocheck = $request->input('ocheck');
$postdata = [
'species' => $species
];
DB::table('dc_pets')
->where('petid', $petid)
->update($postdata);
}
form
<?php echo csrf_field(); ?>
<input type="hidden" name="_method" value="PUT">
.
.
.
<div id="msg">
</div>
To return to list
<a href="<?php echo $vurl; ?>">back</a>
$vurl is my variable to return, create your own.
Validate as needed.
Jeffrey has a free video on put request.