We're finally at the point when we can make bookings, yay.
Goals of This Lesson
- Booking DB Model/Migration
- API endpoint & first successful booking
- Calculating the total price of booking
- Validation: apartment capacity and availability
- Viewing and canceling user's bookings
As usual, covered by tests, so by the end of this lesson, we will have these tests passing:

Booking DB Model/Migration
First, the database structure for that...
In (Show) method in (BookingController):
Are you sure can show the result with trashed when we used Model Binding?
Becouse the method return 404, so the test (test_user_can_cancel_their_booking_but_still_view_it) will fail.
I think we need used query in (Show) method
Not 100% sure actually, but in the repository that test didn't fail. Could you compare to the repository, please?
Yes I compare to repository, still (test_user_can_cancel_their_booking_but_still_view_it) fail.
In these lines assert status 200 but in my test return 404, so the test fail
Just cloned the last version of the repo, and that test passes for me: ✓ user can cancel their booking but still view it
That said, found that another test is failing after my last new lesson, so thanks for reminding me to rerun
php artisan test, need to update another lesson :)Thanks for you, This course is the most course I found it for me, It contains more than learning how to build project.
Any fix for this ?
Yes, I organized the messages in json format like this. app/Exception/Handler.php
I ran test for test_user_can_book_apartment_successfully_but_not_twice() and i got this error message. pls how do i solve it.
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: bookings.start_date (Connection: sqlite, SQL: insert into "booking s" ("apartment_id", "user_id", "total_price", "updated_at", "created_at") values (1, 2, 0, 2023-05-29 02:23:05, 2023-05-29 02:23:05))I am following the course step by stepIt's hard to debug the error for you, as I didn't encounter that error myself. For some reason, the
start_dateis empty in your case, how can it be null, maybe you're not passing it? Every booking needs to have a start_date. Or maybe you haven't defined it in the Factory? Please check your code and compare to the original repository.test_user_can_cancel_their_booking_but_still_view_itfails for me, it doesn't find cancelled (softDeleted) booking. It's strange because in Postman they do work!!@Luis can't really comment or debug without seeing the full code, sorry
Question:
Route::prefix('user')->group(function () { Route::resource('bookings', \App\Http\Controllers\User\BookingController::class); });
You instruct that this route be in routes/web.php, Shouldnt it be in routes/api.php
Thank you for spotting this - indeed it should have been in the API file!