Prashant
Prashant

Reputation: 35

How to insert form values in two different database table in laravel 5.1

How should I save values of form in two different tables in database using laravel. I have two tables one is saving only email and password, second is storing other information of user. How should I do this?

Upvotes: 0

Views: 1468

Answers (1)

djt
djt

Reputation: 7535

Have the form send to a particular Controller method and Store the pertinent data in their relative Models:

public function store(Request $request)
{
   User::create([
       'email' => $request->email,
       'password' => Hash::make($request->password)
   ]);

   Profile::create([
      'website' => $request->website,
      'address' => $request->address,
      // etc...
   ]);

}

Upvotes: 4

Related Questions