Good afternoon, I have a small problem with a query, The table lapses is assigned many OffersUba, in which many EnrolledUba enroll, once those registered are validated the notes (ie, the record is put in the table of notes) that offer (or section) should not be available. The validation is done for all the students at the same time, so I would like to make the query so that if any of the Enrollees already has a record in the notes table, that offer is skipped, but it seems that the - > has () not Is it working, or not as I hope, some help?
The model of lapses:
class Lapso extends Eloquent{
protected $table = 'lapso';
protected $primaryKey = 'lapso';
protected $fillable = array('lapso', 'lapsoActual');
public function ofertauba(){
return $this->hasMany('OfertaUba','lapso');
}
}
The bid model:
class OfertaUba extends Eloquent{
protected $table = 'oferta_uba';
protected $fillable = array('curso', 'nucleo', 'lapso', 'regimen', 'modalidad', 'turno', 'aula', 'dias', 'horas', 'cupos', 'facilitador', 'fecha_inicio', 'fecha_fin', 'fecha_apertura','fecha_cierre');
public function inscritosuba(){
return $this->hasMany('InscritosUba','id_oferta')->orderBy('cedula','asc');
}
public function facilitadores(){
return $this->belongsTo('Facilitadores','facilitador');
}
public function modalidades(){
return $this->belongsTo('Modalidad','modalidad');
}
public function nucleos(){
return $this->belongsTo('Nucleos','nucleo');
}
public function niveles(){
return $this->belongsTo('Niveles','curso','Nivel');
}
public function regimenes(){
return $this->belongsTo('Regimen','regimen');
}
public function lapsos(){
return $this->belongsTo('Lapso','lapso');
}
}
Here is the registration model:
class InscritosUba extends Eloquent{
protected $table = 'inscritos_uba';
protected $fillable = array('cedula', 'curso', 'id_oferta', 'correo', 'telefono','pregunta_asocim','detalle_asocim');
public function ofertauba(){
return $this->belongsTo('OfertaUba','id_oferta');
}
public function estudiante(){
max_execution_time();
return $this->belongsTo('Estudiantes','cedula');
}
public function pagosuba(){
return $this->hasMany('PagosUba','id_inscrito');
}
public function notaFinal(){
max_execution_time();
return $this->hasOne('Notas','CEDULA','cedula')->where('lapso','=',$this->ofertauba->lapso);
}
}
The model of notes:
class Notas extends Eloquent{
protected $table = 'notas';
protected $fillable = array('CEDULA','LAPSO','NRO','NOTA','COD_MAT','SECCION','ORD_LAP','CORTE1','CORTE2','STATUS','COD_NUC');
public $timestamps = false;
protected $primaryKey = null;
public $incrementing = false;
public function nucleos(){
return $this->belongsTo('Nucleos','COD_NUC');
}
}
Here is the query:
public function postObtenerSecciones(){
$curso = Input::get('curso');
$nucleo = Input::get('nucleo');
$lapso = Input::get('lapso');
$secciones = OfertaUba::select('id','curso','lapso','nucleo','seccion')
->where('curso','=',$curso)
->where('nucleo','=',$nucleo)
->where('lapso','=',$lapso)
->whereHas('inscritosuba', function($query){
$query->has('notaFinal','<',1);
})
->get();
}