V
V
Vatrush2019-05-20 18:19:16
Laravel
Vatrush, 2019-05-20 18:19:16

Why is the id of the related table displayed instead of the record id?

Why are id and category_id the same? Everything is fine in the database, the id records are in the correct order and the values ​​are different there.
5ce2c539c96ce508027601.png

public function getUser(Request $request)
    {
        $user = User::where('steamid',$request->name)->first();
        $category = $this->getCategoryUser($user->id);
        return view('layouts/panel', compact('user','category'));
    }
    public function getCategoryUser($id)
    {
        $category = User::find($id)->category;
        return $category;
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vatrush, 2019-05-20
@Vatrush

Decision.
Add pivot to User model:
Call to view in a loop:
$var->pivot->id

A
Alexander Aksentiev, 2019-05-20
@Sanasol

Where is the code?
If you enter another table as a join, then at the output the porridge is obtained from the fields.
It is necessary to specify explicitly in select () what and from where you need to select so that the fields do not overlap each other.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question