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

Yeah, relationships are insanity easy with Laravel. Take a look at the docs: http://laravel.com/docs/4.2/eloquent#relationships

If you keep scrolling down, after eager loading, you will learn how to query and insert data for related models.

Once set up, you can pull out related data really easy. It's one of Laravels sling points.

Hope it helps.

Last updated 2 years ago.
0

ok, I now can save these relationship.

But how can I set the value for $table->integer('value') which I also need in this table?

Last updated 2 years ago.
0

It sends on the relationship type you have set up. One to one, one to many etc?

The docs for inserting are here: http://laravel.com/docs/4.2/eloquent#inserting-related-models

You have a few different options depending on the type of relationship.

Let me know if you get stuck and I'll try to help.

Last updated 2 years ago.
0

Another thing maybe to look into is perhaps using repositories? That way you can make a meta object that on the frontend is simply accessing both tables but as if they were in a single table

Last updated 2 years ago.
0

Sounds like a good idea, but I actually solved it like this:

$user->roles()->attach(1, array('expires' => $expires));

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kay899 kay899 Joined 7 Jul 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.