Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

Turn out, I found a way. But do not know if this is a good way. At least it solve my problem.

$member = model::find($id)->toarray();
$post = new model1;
$post->eventid = 1;
$post->memberid = $id;
$post->name = $member['name'];
$post->save();
Last updated 2 years ago.
0

@chank178 am trying to get user Id from another table and use it as insert in another table how do you do this?

0

MartinGacheru said:

@chank178 am trying to get user Id from another table and use it as insert in another table how do you do this?

@chank178 instead of commenting on a very old thread (3 years old), you should probably start a new topic.

Laravel docs have extensive information how to do this, see https://laravel.com/docs/5.2/eloquent-relationships

Using Eloquent Models you could do something like

$my_thing = App\Thing::find(1); // find the thing object in the database that has id of 1

Then

$my_gadget = App\Gadget::create('name'=>'widget name', 'related_thing_id'=>$my_thing->id);

However you should learn how to do it using relationships, which does it automatically for related models.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

chankl78 chankl78 Joined 2 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.