Courses

Build Laravel API for Car Parking App: Step-By-Step

Price Calculation

Of course, users need to know how much they would pay for parking. It should happen in three phases:

  • Before parking - when getting the list of zones (done)
  • During parking - when getting the parking by ID (not done yet)
  • After parking - as a result of the stopping function (not done yet)

As I mentioned in the very beginning, we won't cover the payments themselves in this tutorial, we only take care of the calculations.

So, we need to create some function to calculate the current price by zone and duration, and then save that price in the parkings.total_price when the parking is stopped.

For that, let's create a separate Service class with a method to calculate the price. In Laravel, there's no Artisan command make:service, so we just create this file manually in the IDE...

The full lesson is only for Premium Members.
Want to access all 10 lessons of this course? (55 min read)

You also get:

  • 69 courses (majority in latest Laravel 11)
  • Premium tutorials
  • Access to repositories
  • Private Discord