dac dac
dac dac

Reputation: 101

After Update, The data from another Table will be deleted

I Have two different database table named Customers and Change_info_request

customers will request of changing their infomation and it will stored in Change_info_request and me the admin will be the one who will approve for changing information. after the update the information inside the Change_info_request will transfer to the Customers table and the data inside the Change_info_request will be deleted .

And that's is my problem, i want to do it in the same controller like this

UpdateRequest

 public function UpdateRequest(ClientUpdate $request){
    $res = Customer::where('id', $request->id)
                    ->update([
                        'first_name'  => $request->new_first_name,
                        'last_name'   => $request->new_last_name,
                        'birthdate'   => $request->new_birthdate,
                        'gender'      => $request->new_gender,
                        'pending_update_info' => 2,

                    ]);
        

    if($res) {
        return response()->wrap($res);
    } else {
        return response()->wrap(["message" => "something went wrong!"]);
    }
}

How will i delete the info from Change_info_request inside this controller ? Sorry for the wrong grammar and im only a student that studying laravel.

Upvotes: 1

Views: 138

Answers (2)

milad hedayatpoor
milad hedayatpoor

Reputation: 636

you have id of that row in Change_info_request table right?

i have done this before this was my way:

i store new information in my table called edit-user (just like your Change_info_request ) and when i show them in admin dashboard i have their id!

when admin click on approve button it will send the id of that row to some function! in function i find the row in edit-user table with id that i have, and replace my new data in my users table (your Customers table) and when i finished replacing data i will delete data from edit-user with that id!

Change_info_request::find('customer_id', $id)->delete();

with id of that row in edit-user(your Change_info_request table) table you can do anything and of course your in Change_info_request table you should have user_id field

good luck!

Upvotes: 1

Atika
Atika

Reputation: 1067

Before your if condition, you can add something like:

$del = Change_info_request::find('customer_id', $request->id)->delete();

Upvotes: 0

Related Questions