mercredi 24 avril 2019

How to get an atribute throw a table in Eloquent?

I have requests table that belongs to subcategories tabla wich belongs to categories table, so from Request model how can I get an atribute from categories?

tables

->requests
id

name

subcategory_id


->subcategories
id

name

category_id


->categories
id

name

color

So I need to get color from Request model, I alredy have the tree models created

class Request extends Model
{
    public function user()
    {
        return $this->belongsTo(User::class)->get();
    }

    public function color()
    {
        $somemagicstuff;

        return $color;
    }
}



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2GCjYMO
via IFTTT

Aucun commentaire:

Enregistrer un commentaire