Simple Eloquent Relationship

Posted 2 years ago by jim1506

I am a newcomer to Laravel which I like, but I find some of the documentation a bit sketchy and I have run into a problem. I am sure it is just me and someone will hopefully will point me in the right direction.

I have a table users and a table countries. Users has a field country_id and both are indexed by id. I have a model User with the following: public function country() { return $this->belongsTo('App\Country'); }

and a model Country with the following (the table has a fields country, abbreviation and flag): public function user() { return $this->hasMany('App/User'); } What I want to do is to call all the users with the attendant info for countries so I can put them into a table. I know this is basic but I admit confusion!

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.