I need to pass all variable data to PHP(Laravel) controller, so as to proceed with other operations with those variables in controller. Here when I do as per below mentioned code, I get response "hello" as output in console. But how do I take input in controller.
Route (web.php)
Route::get('invoice_data_process', 'App\Http\Controllers\InvoiceController@invoiceDataProcess');
Javascript:
$(function() {
$("#print_invoice").on("click", function(e) {
e.preventDefault(); // stop submission
const arr = $("#rowData [id^=product_id]")
.map(function() {
const $qnty = $(this).closest("tr").find("[id^=product_qnty]")
return ({
[$(this).attr("id")]: $(this).val(),
[$qnty.attr("id")]: $qnty.val()
})
})
.get();
var invoiceNo = $('#invoiceNo').val();
var invoiceDate = $('#invoiceDate').val();
var clientName = $('#clientName').val();
var grandTotal = $('#grandtotal').val();
console.log(arr)
$.ajax(
{
type: "POST", //HTTP POST Method
url: '{{ URL::to('/invoice_data_process') }}', // Controller/View
data: { //Passing data
'invoiceNo' : invoiceNo,
'invoiceDate' : invoiceDate,
'clientName' : clientName,
'grandTotal' : grandTotal,
'arr' : arr
},
success: function(response) {
console.log("hello");
},
});
});
});
Controller.php
public function invoiceDataProcess(Request $request)
{
$invoice_number = $request->get('invoiceNo');
$invoice_number = $request->get('invoiceDate');
$client_name = $request->get('ClientName');
$grand_total = $request->get('grandTotal');
$arr = $request->get('arr');
print_r( $invoice_number );
die;
}
Header
<head>
<meta name="csrf-token" content="{{ csrf_token() }}">
</head>
Output (http://127.0.0.1:8000/invoice_data_process)
Blank Page
Route::get, but you're trying to POST to it. Won't workRoute::match(['get', 'post']