vendredi 30 novembre 2018

Laravel restore data from log table

I would like to restore my data from log table which was created on every. I use replicate function for copying all data while update and save to clone table, It works fine to store log data in clone table but i am not sure that how can i restore the data from clone table Here is my code while update

public function update(Request $request, $id){
        $bannerone = Bannersec1::findOrFail($id);

        // every time while edit this will copy old data new clone table 
            $clone = $bannerone->replicate();
            unset($clone['created_at'],$clone['updated_at']);
            $clone['clone'] = $bannerone->id;
            $clone['cloneUser'] = Auth::user()->id;
            $data = json_decode($clone, true);
            Bannersec1clone::create($data);

        // save edited data to database
        $input = $request->all();
        $bannerone->update($input);

        return redirect()->route('bannerone.index')->with('success','Banner Update Successfully');
    }

and this is my code while edit

public function edit($id){
    $bannerone = Bannersec1::findOrFail($id);
    $replicate = Bannersec1clone::where('clone',$id)->orderBy('created_at', 'DESC')->get();

    return view('back.index.banner1.edit', compact('bannerone','replicate'));
}

//So is there any way that i can restore my data from clone table? suppose if i click in test1 -> revision then it will replace with my current data enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire