plutarcomp
9 months ago

Eloquent where from two models

Posted 9 months ago by plutarcomp

I need to get only the available tour from TOURS (this is a model) and the details in TOURSESTACIONE (my second model), im trying this:

$todas = ToursEstacione::with('tours')
                              ->whereBetween('latitude',[($lat - ($dist*0.014)),($lat + ($dist*0.014))])
                              ->whereBetween('longitude',[($long - ($dist*0.014)),($long + ($dist*0.014))])
                              ->get();

i modify my tours model with this:

  public function tours()
    {
      return $this->belongsTo('App\Tour','tour_id')->select('id','name','icon_tour')->where('status',1);
    }

I get all the records in ToursEstacione, but in the label tours i receive only in the ones are with status = 1 a value, the others return null.

I need to receive only the records that has status = 1

Thanks for your help

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