Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

did you specify the relations? can you show your models? something like

class Inspection extend Eloquent {

     public function entries {
         return $this->hasMany('Entries', 'id');
    }
}

class Entries extend Eloquent {

     public function inspection {
          return $this->belongsTo('Inspection', 'id');
     }
}
Last updated 2 years ago.
0

Thanks for the reply jrsalunga. Here are my models. The relationships for Inspection and InspectionEntry both work, entries just get stripped out when its converted to json.

class Inspection extends Eloquent {

    public $timestamps      = false;
    protected $fillable     = array("facility_id", "type", "score", "date", "comply_by", "complied_on");
    protected $guarded      = array("id");
    protected $primaryKey   = "id";
    protected $table        = "inspections";

    public function facility(){
        return $this->belongsTo("Facility", "facility_id", "id");
    }
    
    public function entries(){
        return $this->hasMany("InspectionEntry", "inspection_id", "id")
            ->orderBy("violation", "desc");
    }

}


class InspectionEntry extends Eloquent {

        public $timestamps      = false;
        protected $fillable     = array("inspection_id", "violation", "comment", "memo", "points");
        protected $guarded      = array("id");
        protected $primaryKey   = "id";
        protected $table        = "inspection_entries";

        public function inspection(){
            return $this->belongsTo("Inspection", "inspection_id", "id");
        }

}
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.