A
A
an5432019-03-07 17:58:32
Laravel
an543, 2019-03-07 17:58:32

How to display 4 articles with values ​​from a linked table in Laravel?

Greetings! I want to display the last 4 articles on the main page, I do this:

$new_articles = Article::orderBy('id', 'desc')->where('status', 1)->take(4)->get();

There is a table id | articles_id | country ... The tables are not linked by a foreign key.
How can I display in the template all records from the country table for each of the 4 articles?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shelestov, 2019-03-07
@ShelestovAnt

The wording of the question is not clear...
But who's stopping you from creating the hasMany(Article::class) relation for Country?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question