class Batch extends Model
{
//
public function students()
{
return $this->belongsToMany('App\Models\Student')->using('App\Models\Batch_Student')->withPivot('start_date','end_date','status')->withTimestamps();
}
class Student extends Model
{
//
protected $table = "students";
public function batches()
{
return $this->belongsToMany('App\Models\Batch')->using('App\Models\Batch_Student')->withPivot('start_date','end_date','status')->withTimestamps();
}
class Batch_Student extends Pivot
{
//
protected $table = "batch_student";
public function student()
{
return $this->belongsTo('App\Models\Student');
}
public function batch()
{
return $this->belongsTo('App\Models\Batch');
}
public function attendance()
{
return $this->hasManyThrough('App\Models\Student_Attendance', 'App\Models\Batch');
}
}
class Student_Attendance extends Model
{
//
protected $table = "student_attendances";
public function students()
{
return $this->hasMany(
'App\Models\Student'
);
}
public function batches()
{
return $this->hasMany('App\Models\Batch');
}
}
Basically i want to fetch student attendance record which is stored in student_attendance table along with student details which is stored in student table according to the selected batch.