I've been stucked on this line of code that Im doing. It says that mthod is not allowed however I already made some fix to accept the request
Services Controller
public function peakmode(Request $request, $id)
{
$command = new \App\BizCommands\UpdatePeakmodeServices();
$arr = $request->all();
//$arr["merchant_id"] = $this->get_id();
$service->merchant_id = 1;
$arr["id"] = $id;
$ret = $command->execute($arr, Auth::user());
//return response()->json(['success'=> ($ret->error_code==0), 'message'=> $ret->message]);
$message = array('message' => 'Service Successfully Updated!');
return redirect()->back()->with($message);
}
Blade Form
<form action="{{ route('services.peakmode', $service->id) }} ">
{{method_field('PUT')}}
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="serviceswitch-7838" service-id="{{ $service->id }}">
<label class="onoffswitch-label" for="serviceswitch-7838"> <span class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span> </label>
Ajax Script
$(".onoffswitch .onoffswitch-checkbox").on("change",function(e){
service_id = $(this).attr('service-id');
if($(this).is(':checked') ){
peak = 1;
}else{
peak = 0;
}
$.ajax({
method: "POST",
url: $(this).prop('action'),
data: {
service_id: service_id,
peak: peak,
'_method': 'PUT',
"_token": "{{ csrf_token() }}",
}
})
.done(function(response){
console.log(response);
});
});
Route
Route::post('/merchant/services/peakmode/{id}', 'Merchant\ServicesController@peakmode')->name('services.peakmode');