Is there any method for one-to-one correlation between laravel tables in the middle?

borrow one-to-many examples from the remote layer of the official website

posts

  • id-integer
  • user_id-integer

users

  • id-integer
  • country_id-integer
  • name-string

countries

  • id-integer
  • name-string

now my business logic is on posts .
my requirement is that I associate the users table in posts , get some data of users , and
need to use country_id of users table to get id,name data
of countries table.

Aug.10,2021

isn't this just a join query?


A novice who has just learned laravel for a day.. The problem has just been solved on a whim. That is, user with country


at the same time of posts belongsto user.

clipboard.png

clipboard.png

well, there are two ways to find the answer, one is to use laravel hasOneThrough, but this version needs to support
, the other is to directly normal with intermediate table B model, C model,-> with ('B.C')
B model to associate one-to-one C model, but there is a problem that the method name must be the model name. Currently, there is no other naming reason

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e4758b-44c3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e4758b-44c3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?