alenavafer
4 years ago

Access data 3 tables

Posted 4 years ago by alenavafer

Hi, I have 3 tables

users (id, name, lastname)
extra (id, title)
users_extras (id, user_id, extra_id)

If I want to know how extra data from a user I write this in users model

public function extras()
    {
        return $this->belongsToMany('App\Extras', 'users_extras', 'user_id', 'id');
    }

But I have an error "Undefined property: Illuminate\Database\Eloquent\Collection::$extras"

What is wrong, I am new in Laravel.

Thanks

Please sign in or create an account to participate in this conversation.