lundi 19 août 2019

Displaying single resource for specific user

I want to display a single reservation resource for specific user in an API application when a get request is made to this route localhost:8000/api/user/{user}/reservations/{reservation} and the user should then be able to view the details of the reservation made.

Tried testing by making a get request to localhost:8000/api/user/1/reservations/1 but nothing is returned.

Here's the controller method that should be returning the reservation

<?php

namespace App\Http\Controllers;

use App\User;
use App\Reservation;

...

public function showReservation(User $user, Reservation $reservation)
{
    if (auth()->user() == $user) {

        $reservedProduct = new ReservationResource(Reservation::where('user_id', $user->id)->where('id', $reservation->id)->first());

        return response()->json(['reservation' => $reservedProduct]);
    }
}

Can anyone tell me why my code doesn't work? Keep in mind that there is actually a reserved product made by this user



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2KYEvNF
via IFTTT

Aucun commentaire:

Enregistrer un commentaire