我想通过资源控制器使用帖子类型ajax请求将表单数据存储在数据库中,但是它给了我错误 POST http://localhost:8000/reservations 405(方法不允许)
$('#btn_add').click(function() {
$('#user-form').ajaxSubmit({
type: 'POST',
url: '{!! url($route)!!}', //it's http://localhost:8000/reservations
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(result) {
console.log(result);
$('#user_up_stat').addClass('modal-' + result['type']);
$('#user_up_stat_title').html(result['status']);
$('#user_up_stat_msg').html(result['msg']);
$('#user_up_stat').modal('show');
},
error: function(response){
console.log(response);
}
});
});
public function store(Request $request)
{
$this->check();
if($request->name == null || $request->name == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to Update enter a valid name."];
if($request->email == null || $request->email == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to create select a valid email."];
if($request->phone == null || $request->phone == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to update enter a valid phone number."];
if($request->address == null || $request->address == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to update enter a valid address."];
if($request->checkin_date == null || $request->checkin_date == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to update enter a valid check in date."];
if($request->checkout_date == null || $request->checkout_date == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to update enter a valid check out date."];
if($request->room_id == null || $request->room_id == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to Update enter a valid room id."];
if($request->card_name == null || $request->card_name == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to update enter a valid card name."];
if($request->card_number == null || $request->card_number == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to update enter a valid card number."];
if($request->expiry_date == null || $request->expiry_date == '')
return ['status'=>'Error','type'=>'danger','msg'=>"Unable to update enter a valid expiry date."];
$reservations=new Reservation();
$reservations->name = $request->name;
$reservations->email = $request->email;
$reservations->address = $request->address;
$reservations->checkin_date = $request->checkin_date;
$reservations->checkout_date = $request->checkout_date;
$reservations->room_id = $request->room_id;
$reservations->card_name = $request->card_name;
$reservations->card_number = $request->card_number;
$reservations->expiry_date = $request->expiry_date;
if($request->has('card_type'))
$reservations->card_type = $request->card_type;
$reservations->save();
return ['status'=>'Success','type'=>'success','msg'=>'Reservation updated successfully.'];
}
Route::resource('/reservations' , 'ReservationsController');