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

Onouris's avatar

Problem with Relation Eloquent

Hi, I have little problem with a relation on OVH shared hosting (local doesn't have this problem). I want to retrieve category from an article. Relation is Article => Type => Category. My request is :

$articles  = Article::with('type', 'type.category')->get();

But I have for each article :

$article->type->category = null;

My different models :

*ArticleModel*/
public function type(){
    $this->belongsTo('App\Model\Type');
}

/*TypeModel*/
public function category(){
    $this->belongsTo('App\Model\Category');
}

I show the query on categories table in the debugbar.

SELECT * FROM categories WHERE id IN (listOfDifferentId)

You have ideas to fix this bug?

PS : sorry for my poor english.

0 likes
0 replies

Please or to participate in this conversation.