dimanche 28 août 2016

how can i use relationship in laravel?

My schema is as follows:

channel table:
id int unsigned primary key auto increment,
name varchar(30) not null,
...

category table:
id int unsigned primary key auto increment,
channel_id int unsigned index,
name varchar(30) not null,
...

article table:
id int unsigned primary key auto increment,
category_id int unsigned index,
title varchar(90) not null,
content text not null,
...

so, every article belong to a specific category and the category belongs to a specific channel.

my question is:

how can i search all the articles with the category name and channel name (the relationship is ready in my code)?

i have tried

$articles = App\Article::latest()->with('category')->with('channel')->get();

but it does not work, anyone who can help me? thank you for your time.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire