A
A
Abc Edc2015-12-04 15:03:30
Laravel
Abc Edc, 2015-12-04 15:03:30

Why is selection not working in laravel?

The News entity has a source_id field (owned by companies)
In Company

public function news()
    {
        return $this->hasMany('App\News', 'source_id', 'id');
    }

So Argument 2 passed to Illuminate\Database\Eloquent\Relations\ HasMany
::match() must be an instance of Illuminate\Database\Eloquent\Collection, instance of App\CustomCollection\SupportsCollection given, called in
What's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
D', 2015-12-04
@gleber1

What is App\CustomCollection\SupportsCollection?
Direct text is written that the wrong type of a collection is transferred.
What is App\CustomCollection\SupportsCollection and where does it come from?

N
newpy, 2015-12-04
@newpy

First of all, they most likely mixed up the order of the passed parameters: the
first is foreign_key, the second is local_key.
Secondly, they could also confuse entities, judging by your words.

class News
public function company()
{
     return $this->hasMany('App\Company', 'id', 'source_id');
}

class Company
public function news()
{
     return $this->belongsTo('App\News');
}

Thirdly: it would be worthwhile to understand the relationship between your entities. Because your words only confuse. Describe the Company and News entities. For example: many/one Company may own many News, many News may belong to one/many Companies. Since it actually depends on this how to correctly describe relationships (relations) in models. I am sure that if you scribble yourself on a piece of paper in such a simple text, then it will become clearer to you what and where to prescribe, and how to write it correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question