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();
@chank178 am trying to get user Id from another table and use it as insert in another table how do you do this?
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community