Skip to main content

"Black Friday" Discount! Only until December 1st: 50% off all membership plans!

Read more here

Parking list and Stop parking

Premium
6 min read
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