laravel fetch request code example
Example 1: laravel fetch post
fetch(url, {
headers: {
"Content-Type": "application/json",
"Accept": "application/json, text-plain, */*",
"X-Requested-With": "XMLHttpRequest",
"X-CSRF-TOKEN": token
},
method: 'post',
credentials: "same-origin",
body: JSON.stringify({ name: name, number: number }) })
.then((data) => {
form.reset();
window.location.href = redirect;
})
.catch(function(error) {
console.log(error);
});
}
Example 2: laravel get all request parameters
$request->input('name');
$request->input('user.name');
Example 3: how to see with page reuested in laravel
$request->fullUrl()