app/Http/Controllers/Admin/RideController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Ride  $ride
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(UpdateRideRequest $request, Ride $ride)
    {
        if ($request->ride_type == 'cyclic') {
            $rideData = array_merge($request->validated(), ['ride_date' => null]);
            $requestData = collect($request->validated());
            $days = collect($this->dayNames)
                ->mapWithKeys(fn ($item) => [$item => 0])
                ->replace($requestData->get('days'));
            $rideScheduleData = $requestData
                ->only('start_date', 'end_date')
                ->merge($days)
                ->toArray();
            $ride->update($rideData);
            $ride->schedule()->updateOrCreate(['ride_id' => $ride->id], $rideScheduleData);
        } else {
            $ride->update($request->validated());
            $ride->schedule()->delete();
        }
        return redirect()->route('admin.rides.index')
            ->withSuccess('The ride has been successfully updated!');
    }
public function update ( UpdateRideRequest $ request , Ride $ ride ) { if ( $ request -> ride_type == 'cyclic' ) { $ rideData = array_merge ( $ request -> validated ( ) , [ 'ride_date' => null ] ) ; $ requestData = collect ( $ request -> validated ( ) ) ; $ days = collect ( $ this -> dayNames ) -> mapWithKeys ( fn ( $ item ) => [ $ item => 0 ] ) -> replace ( $ requestData -> get ( 'days' ) ) ; $ rideScheduleData = $ requestData -> only ( 'start_date' , 'end_date' ) -> merge ( $ days ) -> toArray ( ) ; $ ride -> update ( $ rideData ) ; $ ride -> schedule ( ) -> updateOrCreate ( [ 'ride_id' => $ ride -> id ] , $ rideScheduleData ) ; } else { $ ride -> update ( $ request -> validated ( ) ) ; $ ride -> schedule ( ) -> delete ( ) ; } return redirect ( ) -> route ( 'admin.rides.index' ) -> withSuccess ( 'The ride has been successfully updated!' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
//