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

Perhaps you don't need a pivot table using has many it is more like a post with articles. Also I believe there is a laracast on that very subject you are trying to do.

0

jimgwhit said:

Perhaps you don't need a pivot table using has many it is more like a post with articles. Also I believe there is a laracast on that very subject you are trying to do.

I have already watched some of laracast's videos and I did the exact same thing as shown in the video... I'm not sure what you mean

0

See this ==https://scotch.io/tutorials/a-guide-to-using-eloquent-orm-in-laravel. Also. http://laravel.io/forum/search?query=hasmany. http://laravel.io/forum/search?query=one+to+many and. http://laravel.com/docs/5.0/eloquent#one-to-many

Last updated 9 years ago.
0
Solution

First off in the first code you're referencing you are outputting a column "user_id" from a find query, not the user method you have defined.

Secondly do you have any records under the ID 1 in both the users and history tables?

Last updated 9 years ago.
0

lnenad said:

First off in the first code you're referencing you are outputting a column "user_id" from a find query, not the user method you have defined.

Secondly do you have any records under the ID 1 in both the users and history tables?

That was one of the things I did wrong. The other thing was that I created a history row the wrong way. I did this:

$history = History::create(["user_id" => User::find(1), "video_name" => "example"]);

insted of:

$history = History::create(["user_id" => 1, "video_name" => "example"]);

BTW, how come the first row didn't show any errors since I was assigning object to a column?

I would also like to thank everyone for their help.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

AppexX appexx Joined 2 Apr 2015

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.