I'm trying to work with foreign keys on Laravel. It's quite simple how to add foreign key on table. But if table can contain more than one foreign key, for example:
Table posts
:
id,
post_title
post_content
post_category (can be more than one)
Table category
id,
category_title,
--
I want to get posts list with each category_title. I tried this:
$data = DB::table('posts')
->join('post_category', 'posts.post_category', '=', 'post_category.id')
->orderBy('id', 'DESC')
->paginate(10);
And the result:
But it just get 1 category name instead of 2. How can i get posts list with each category_title (not id) included?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Xa2HmN
via IFTTT
Aucun commentaire:
Enregistrer un commentaire