I have 3 models, Trials has one sample and track has one trial, I need to access sample name, I try to do this but get this error:
BadMethodCallException in Builder.php line 2024: Call to undefined method Illuminate\Database\Query\Builder::samples()
Controller:
public function track($id){
$tracks = track::with('trials')->with('samples')->where('trials_id',$id)->get();
return view('Tracks.index',compact('tracks'));
}
Samples:
class samples extends Model
{
protected $fillable = ['variety'];
public function Trials()
{
return $this->belongsTo('App\trial');
}
Trial:
class trial extends Model
{
protected $fillable = ['amount','date','comments','code'];
public function Samples()
{
return $this->hasOne('App\samples', 'id', 'samples_id');
}
public function Track()
{
return $this->belongsTo('App\track');
}
}
Tracks:
class track extends Model
{
public function Trials()
{
return $this->hasOne('App\trial', 'id', 'trials_id');
}
}