I'm encountering a problem here. The error message reads "Too few arguments to function App\Http\Controllers\ViewsController::OBviews(), 0 passed and exactly 1 expected"
Here is my controller:
public function OBviews($date)
{
$masterIds = DB::select('SELECT * FROM o_b_masters OBM INNER JOIN users u on OBM.emp_id = u.id INNER JOIN o_b_requests OBR
on OBR.details_id = OBM.obmaster_id WHERE u.id =? AND MONTH(OBM.date_filed) = ?', [Auth::id(), $date]);
return response()->json($masterIds);
}
This is my route:
Route::GET('/obView/{date}', 'ViewsController@OBviews')->name('OBRequest');
Below is the JavaScript code:
$('select').on('change', function (e) {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
alert(valueSelected);
$.ajax({
url: 'obView',
type: 'GET',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: 'date='+valueSelected,
success: function (data) {
if (data['success']) {
alert(data['success']);
} else if (data['error']) {
alert(data['error']);
} else {
alert('Whoops Something went wrong!!');
}
},
error: function (data) {
alert(data.responseText);
}
});
});
In my details.blade.php file:
<select name="month" class="form-control">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
It appears that when there are changes, nothing gets passed to the controller.