Skip to main content

Parking list and Stop parking

Premium
6 min read

In this lesson, we will display an active parking list with a stop button to end parking.

Active parkings list

1. Two new methods

Let's add two more methods into src/stores/parking.js...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Zain Amin avatar

I noticed that the API for the parking list is missing. (https://laraveldaily.com/lesson/build-laravel-api-step-by-step/start-stop-parking)

👀 1
Huy Nguyen avatar

You can add this route to api.php file, this is in middleware

Route::middleware('auth:sanctum')->group(function () {
...
Route::get('parkings', [\App\Http\Controllers\Api\V1\ParkingController::class, 'index'])->name('parkings.index');
...
})

Then add this action to ParkingController

public function index(Request $request)
{
return new ResponseSuccess(ParkingResource::collection(Parking::with('vehicle')->whereNull('stop_time')->get()));
}
Karolis avatar

We already have active scope in the Parking model. Another way to write this method could be:

public function index()
{
return ParkingResource::collection(Parking::with('vehicle', 'zone')->active()->get());
}

Do not forget to put zone model for the zone name and price.

🥳 1
Ngozi Stephen Onyemauche avatar
Ngozi Stephen Onyemauche

Pls my active parking list is not showing with a stop button i don't know what might be the problem