hasMany undefined property

Posted 3 years ago by netcore

Hello. I have problem in my code.

Table structure

articles
  -id
  -title
  -category

categories
  -id
  -title
  -slug

This is code method on Category model - http://prntscr.com/80i0zx

This is code in controller -

$category = Category::all()->articles;
return dd($category);

After return I get this ErrorException in ArticlesController.php line 108: Undefined property: Illuminate\Database\Eloquent\Collection::$articles

What is wrong there? Please help me

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