app/Http/Controllers/SurveyController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $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(Survey $survey)
    {
        try{
            $validator = Validator::make(request()->all(),[
                'title' => "required|unique:surveys,title,{$survey->id}",
            ]);
            if ($validator->fails()) {
                return redirect()->back()->withErrors($validator)->withInput();
            }
            $data = request()->all();
            if(array_key_exists('is_active',$data)){
                $data['is_active']=1;
            }else{
                $data['is_active']=0;
            }
            $data['updated_by'] = auth()->user()->id??null;
            $survey->update($data);
            return redirect(route('surveys.index'))->withSuccess('Data Updted Successfully!');
        } catch (Exception $e) {
            return redirect()->back()->withDanger($e->getMessage());
        }
    }
public function update ( Survey $ survey ) { try { $ validator = Validator :: make ( request ( ) -> all ( ) , [ 'title' => " required|unique:surveys,title, { $ survey -> id } " , ] ) ; if ( $ validator -> fails ( ) ) { return redirect ( ) -> back ( ) -> withErrors ( $ validator ) -> withInput ( ) ; } $ data = request ( ) -> all ( ) ; if ( array_key_exists ( 'is_active' , $ data ) ) { $ data [ 'is_active' ] = 1 ; } else { $ data [ 'is_active' ] = 0 ; } $ data [ 'updated_by' ] = auth ( ) -> user ( ) -> id ?? null ; $ survey -> update ( $ data ) ; return redirect ( route ( 'surveys.index' ) ) -> withSuccess ( 'Data Updted Successfully!' ) ; } catch ( Exception $ e ) { return redirect ( ) -> back ( ) -> withDanger ( $ e -> getMessage ( ) ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .