I can't create new database record, because after submit it always shows POST 405 (not allowed). I tried to move laravel routes from api.php to web.php but it didn't work. Also tried to modificate axios.post link (create, /create, localhost://Reservationsystem/public/create) but it also didn't gave me result.
Web.php
Route::resource('/reservation','ReservationController');
Route::get('/{any}', 'SinglePageController@index')->where('any', '.*');
Routes.js
import Vue from 'vue'
import Router from 'vue-router'
import Home from './components/HomeComponent.vue'
import Reservations from './components/ReservationsComponent.vue'
Vue.use(Router);
export default new Router({
routes: [
{
path: '/',
name: 'home',
component: Home
},
{
path: '/reservations',
name: 'reservations',
component: Reservations
}
]
})
HomeComponent.vue
<script>
import axios from 'axios';
export default {
data: function () {
return {
reservation: {
name: '',
surname: '',
email: '',
date: '',
place: ''
}
}
},
methods: {
addReservation: function () {
let uri = 'reservation';
axios.post(uri, this.reservation).then(res => this.reservation = [...this.reservation, res.data]);
}
}
}
</script>
controller method:
public function store(Request $request)
{
$reservation= new Reservation($request->all());
$reservation->save();
return new ReservationResource($reservation);
}
public function store?Route::resource('/reservation','ReservationController');inapi.phpand make the axios call to/api/reservationurl.