File: /home/cursos.ril.es/app/Cursos.php
<?php
namespace App;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
class Cursos extends Model
{
protected $table = 'cursos';
protected $fillable = array('idCategoria', 'fechaFin', 'idProfesor', 'numMax', 'numMin', 'resumen', 'mailAntes','mailDEspues','descripcion','fechasInfo','programa','faq', 'lugar', 'imagen', 'fechaInicio', 'duracion', 'horario', 'precios', 'contenidoHtml', 'slug', 'precios_texto', 'plazas', 'title_seo', 'fecha_texto');
/**
* Obtiene los alumnos del curso.
*/
public function userscursos()
{
return $this->hasMany('App\UsersCursos');
}
/**
* Relación con Alumnos
*/
public function users()
{
return $this->belongsToMany('App\User','users_cursos','cursos_id','users_id');
}
public function listaesperacursos()
{
return $this->hasMany('App\ListaEspera');
}
public function interesado() {
foreach ($this->listainteresadoscursos()->get() as $interesado) {
if ($interesado->users_id == Auth::user()->id) {
return true;
}
}
return false;
}
public function tienePlazas() {
if ($this->numMax <= $this->userscursos()->count()) {
return false;
}
return true;
}
public function listainteresadoscursos()
{
return $this->hasMany('App\ListaInteresados');
}
public function categoria()
{
return $this->belongsTo('App\Categorias', 'idCategoria');
}
public function profesor()
{
return $this->belongsTo('App\Profesores', 'idProfesor');
}
public function terminado() {
if ($this->fechaInicio < Carbon::now()->format('Y-m-d')) {
return true;
}
return false;
}
public function scopeFoto($query) {
return $query->whereBetween('idCategoria', [6,7]);
}
public function scopePlazas($query,$alumnos)
{
return $query->where('numMax', '>', count($alumnos));
}
public function scopeActivos($query) {
return $query->where('fechaInicio', '>=', Carbon::now()->format('Y-m-d'));
}
public function scropeProximos($query) {
return $query->where('fechaInicio', '>=', Carbon::now()->addWeek()->format('Y-m-d'));
}
public function scopeFinalizados($query) {
return $query->where('fechaFin', '>', Carbon::now()->format('Y-m-d'));
}
}