Skip to content
Advertisement

Get a value from two tables

I am trying to get the value of the colum “name” from the clubs table.

First table:(Clubs)

  • id*
  • name (what i need!!!)
  • email
  • password

Second table:(club_posts)

  • id
  • club_id*
  • zip_id
  • kategory
  • type
  • stadt
  • plz

Controller:

This is my query:

The result is an array with ten values, but need only one.enter image description here

Advertisement

Answer

Create a relation club in you ClubPost Model so that you can access the club of that club post using the relation.

ClubPost Model

Now if you want to access the name(or any other property) of the club for a club post, you can use the club relation.

In your blade, you’d be looping over the $club_posts.

Also, eager load the club relation in your controller.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement