79134886

Date: 2024-10-28 19:45:17
Score: 0.5
Natty:
Report link

The issue is that you are trying to cast a method which is not a column that is wrong if you want to cast or change the result to array use this approch

$yourModel->skills->toArray()

And lastly, the problem with it returning one result is that it's trying to fetch a row using the Skill model that matches the model id assuming the Skill have the id as primary_key; there will only be one element in that table in skills table that matches YourModel id that was the reason that was returning 1 data, to correct that, remove the id and replace it with the foreign_key For more reference, use this link: laravel doc

public function skills(){
      return $this->hasMany(Skill::class,'foreign_key');
    }
Reasons:
  • Blacklisted phrase (1): this link
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: henok tesfu