Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

pickab00's avatar

How to take multiple values from one column in laravel

Ok so the question maybe broad but I will try to explain as best as I can.

Basically I have a “tags” table and a “posts” table. As I am using eloquent, my posts table has a column named named. This column will basically enter the tags tables ta in to the posts tables tables.

What I currently do not get is, how can I fetch the data? Assuming this is my code:

$postsWithTags = Post::with(‘tags’)->get();

And now I could just use a @foreach in my blade and get the column named tag_id data. But here is the thing. If my tag_id column had this data (1, 2, 3, 4), how can I fetch that data and display the actual tag name?

I have a tags table and a posts table. And I am using a single column in posts table named tag_id to store multiple tag id from tags table (this is a summary of what I just explained).

Is there any better ways to achieve this? Do I need to create a separate table? Or stick with this? And how can I take the multiple values from one column which data is something like this (1, 2, 3, 4) and also display the tag name.

0 likes
1 reply

Please or to participate in this conversation.