Level 2
Make it
Route::post('/booking', 'BookingController@create')->name(create); Route::post('/booking', 'BookingController@update')->name(update);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, could anyone explain to me what is failing in my app?
This is what I'm trying to do:
BOOKINGSYSTEM.VUE
randomString: function (length) {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = length;
var str = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
str += chars.substring(rnum,rnum+1);
}
return str;
},
createBooking: function(e) {
e.preventDefault();
e.stopPropagation();
this.checkUserForm();
this.checkCarForm();
this.checkTimeForm();
this.checkTermsForm();
let str1 = this.randomString(8);
let str2 = this.randomString(8);
let randomKey = str1+str2;
axios.post('/api/create/booking', {
name: this.booking.name,
socialId: this.booking.socialId,
email: this.booking.email,
phone: this.booking.phone,
carNumber: this.booking.carNumber,
carSize: this.booking.carSize,
carMake: this.booking.carMake,
carType: this.booking.carType,
carColor: this.booking.carColor,
dropOffDate: dayjs(this.booking.dropOffDate).format('DD/MM/YYYY'),
dropOffTime: this.booking.dropOffTime,
pickUpDate: dayjs(this.booking.pickUpDate).format('DD/MM/YYYY'),
pickUpTime: this.booking.pickUpTime,
numberOfDays: this.booking.numberOfDays,
accepted_terms: this.booking.termsChecked,
checkedService: this.booking.checkedService,
discountUsed: this.couponInput,
priceForServices: this.servicesPrice,
priceForStorage: this.daysPrice,
price: this.finalPrice,
step: 1,
randomKey: randomKey
})
.then(response => {
var kortaLinkUrl = 'https://netgreidslur.korta.is;
window.location.href = kortaLinkUrl;
return false;
});
return false;
}
api.php
Route::post('/booking/create', 'BookingController@create');
Route::post('/booking/update', 'BookingController@update');
BookingController
public function create(Request $request)
{
$validator = $request->validate([
'name' => 'required',
'socialId' => 'required',
'email' => 'required',
'phone' => 'required',
'carNumber' => 'required',
'carSize' => 'required',
'carMake' => 'required',
'carType' => 'required',
'carColor' => 'required',
'dropOffDate' => 'required',
'dropOffTime' => 'required',
'pickUpDate' => 'required',
'pickUpTime' => 'required',
'accepted_terms' => 'required',
'price' => 'required'
]);
$booking = Booking::create([
'user_id' => auth()->id(),
'name' => $request->name,
'socialId' => $request->socialId,
'email' => $request->email,
'phone' => $request->phone,
'carNumber' => $request->carNumber,
'carSize' => $request->carSize,
'carMake' => $request->carMake,
'carType' => $request->carType,
'carColor' => $request->carColor,
'dropOffDate' => $request->dropOffDate,
'dropOffTime' => $request->dropOffTime,
'pickUpDate' => $request->pickUpDate,
'pickUpTime' => $request->pickUpTime,
'numberOfDays' => $request->numberOfDays,
'accepted_terms' => $request->accepted_terms,
'discountUsed' => $request->discountUsed,
'priceForServices' => $request->priceForServices,
'priceForStorage' => $request->priceForStorage,
'price' => $request->price,
'step' => $request->step,
'randomKey' => $request->randomKey
]);
if (!empty($request->checkedService)) {
$booking->services()->attach($request->checkedService);
}
if (request()->wantsJson()) {
return $booking;
}
return $booking;
}
@hjortur17 your route is defined as /booking/create, but you're trying to access /create/booking.
Please or to participate in this conversation.