binggle
4 months ago

'whereHas' just return the last record..

Posted 4 months ago by binggle

I want to retrive all Events records with belongsTo relationship ( Type )

But it gives me just one last Event record .

Can someone help me ?

in Controller .

$events = Event::where('weekday', $weekday)
            ->whereHas('type', function(  $q) use($type) {
                 $q->where('key',  $type);
            })->get();

Event.php

class Event extends Model {


    function type(){
        return $this->belongsTo('App\Type');   
    }
    

}

Type.php

class BetType extends Model {
        
    function events(){
        return $this->hasMany( App\Event::class);
    }

}

TIA

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