M
M
Mile43111122020-04-24 12:49:46
Laravel
Mile4311112, 2020-04-24 12:49:46

Why Laravel whereHas relation doesn't work?

public function getNews(){
        return $this->hasMany(News::class, 'user_id');
}


$user = User::query()
            ->with('getNews')
            ->whereHas('getNews', function($query){
                $query->limit(2);
            })
            ->where('id', $id)
            ->first();


5ea2b600bbdf0585055465.png

there should be 2, why 3????

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-04-24
@JhaoDa

We look at a huge die with an exclamation point.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question