C
C
CHtommy2022-02-21 18:54:08
PHP
CHtommy, 2022-02-21 18:54:08

How to get data from many to many correctly?

Hello, I made MTM as in the documentation and the problem is that I use MTM in the form of getting tags from posts.
Inside the post, everything works fine, but outside - no. I would like to place them on the main page via "@foreach"
6213b53e5d6d6868547614.png

https://github.com/ChampionTommy/laravel-blog/tree... - models
https://github.com/ChampionTommy/laravel-blog/tree.. . -db

I can't figure out how it's done? Maybe I didn't look at the documentation properly or missed something...Poke your finger please...
Tried via Tinker - Tags::with('posts')->first() and get null. But it highlights the tags with the usual get ()
As if I have no connection with the posts model

upd: Perhaps I should specify the post_id in the db Tags and take the value from there, it happened to me when I did "one to many"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2022-02-21
@jazzus

At you communications are registered polymorphic. There is no database schema.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question