Nishanth  Nishanth - 1 year ago 45
PHP Question

Update two tables using laravel

Hi how can i update a values in two tables my code as shown as below cases:

public function subscriberprofileupdate($ids, Request $request) {
$profile = Subscriberinfo::find($ids);
$id = \Auth::user()->id;
$user_id = \Auth::user()->user_id;
$subscriber_id = \Auth::user()->subscriber_id;
$inputteacher = $request->all();

$profile->contact_person_firstname = $inputteacher['contact_person_firstname'];
$profile->contact_person_lastname = $inputteacher['contact_person_lastname'];
$profile->email = $inputteacher['email'];
$profile->save();
return Redirect('/subscriber/profile');
}


If i can update email in subscriber table means that it will also update on users table also by using the user_id.
How can i make it.

Answer Source

You can simply:

User::where('id',$user_id)->update(['email' => $inputteacher['email']]);

It will update the Users table email where users.id is $user_id

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download