app/Http/Controllers/SurveyController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \App\Http\Requests\UpdateSurveyRequest  $request
     * @param  \App\Models\Survey  $survey
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(UpdateSurveyRequest $request, Survey $survey)
    {
        $data = $request->validated();
        if (isset($data['image'])) {
            $relativePath = $this->saveImage($data['image']);
            $data['image'] = $relativePath;
            if ($survey->image) {
                $absolutePath = public_path($survey->image);
                File::delete($absolutePath);
            }
        }
        $survey->update($data);
        return new SurveyResource($survey);
    }
public function update ( UpdateSurveyRequest $ request , Survey $ survey ) { $ data = $ request -> validated ( ) ; if ( isset ( $ data [ 'image' ] ) ) { $ relativePath = $ this -> saveImage ( $ data [ 'image' ] ) ; $ data [ 'image' ] = $ relativePath ; if ( $ survey -> image ) { $ absolutePath = public_path ( $ survey -> image ) ; File :: delete ( $ absolutePath ) ; } } $ survey -> update ( $ data ) ; return new SurveyResource ( $ survey ) ; }
Update the specified resource in storage.
Update the specified resource in storage .