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

BrownieCoffee's avatar

Join to tables

Hi there,

I want to join projects table and categories table together to get project category name

my table project

- id 

- category_id

my table categories

- id 

- name

with this code $pro = Project::join('categories', 'projects.category_id', 'categories.id')->get(); I have this result below:

dump(project)

        "id" => 3
        "user_id" => 1
        "category_id" => 3
    ...
        "name" => "Beauté"
 

I would like to have category name unstead.

Is it possible ?

Thank you in advance for you help.

see you.

0 likes
2 replies
Tray2's avatar

You can use something like this

$project = Project::with('categories')->get()

or just do this in your view

$project->category()->name;

Please or to participate in this conversation.