app/Http/Controllers/Backsite/DoctorController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(UpdateDoctorRequest $request, Doctor $doctor)
    {
        $data = $request->all();
        $data['fee'] = str_replace(',', '', $data['fee']);
        $data['fee'] = str_replace('IDR ', '', $data['fee']);
        if(isset($data['photo'])){
            $get_item = $doctor['photo'];
            $data['photo'] = $request->file('photo')->store(
                'assets/file-doctor', 'public'
            );
            $data_old = 'storage/'.$get_item;
            if (File::exists($data_old)) {
                File::delete($data_old);
            }else{
                File::delete('storage/app/public/'.$get_item);
            }
        }
        $doctor->update($data);
        alert()->success('Success Message', 'Successfully updated doctor');
        return redirect()->route('backsite.doctor.index');
    }
public function update ( UpdateDoctorRequest $ request , Doctor $ doctor ) { $ data = $ request -> all ( ) ; $ data [ 'fee' ] = str_replace ( ',' , '' , $ data [ 'fee' ] ) ; $ data [ 'fee' ] = str_replace ( 'IDR ' , '' , $ data [ 'fee' ] ) ; if ( isset ( $ data [ 'photo' ] ) ) { $ get_item = $ doctor [ 'photo' ] ; $ data [ 'photo' ] = $ request -> file ( 'photo' ) -> store ( 'assets/file-doctor' , 'public' ) ; $ data_old = 'storage/' . $ get_item ; if ( File :: exists ( $ data_old ) ) { File :: delete ( $ data_old ) ; } else { File :: delete ( 'storage/app/public/' . $ get_item ) ; } } $ doctor -> update ( $ data ) ; alert ( ) -> success ( 'Success Message' , 'Successfully updated doctor' ) ; return redirect ( ) -> route ( 'backsite.doctor.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// get all request from frontsite // re format before push to table // upload process here // change format photo // first checking old photo to delete from storage // change file locations // delete old photo from storage // update to database