vendredi 16 novembre 2018

auth()->user()->id is not working when I use it in controller using routes to api.php

public function store(Request $request)
    {
        $booking = ($request->isMethod('put')) ? Booking::findOrFail($request->booking_id) : new Booking;
        $booking->checkIn = $request->checkIn;
        $booking->checkOut = $request->checkOut;
        $booking->room_id = $request->room_id;
        $booking->user_id = auth()->user()->id;//not working

        if($booking->save()){
            return new BookingResource($booking);
        }
    }

Route::put('/booking','BookingsController@store');//api.php

Here auth()->user()->id is not working but its working find if i use it the same code but route code in routes/web.php



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire