You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.3 KiB
PHTML

2 months ago
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Pregunta extends Model
{
use HasFactory;
protected $table = 'preguntas';
protected $fillable = [
'curso_id',
'enunciado',
'imagenes',
'enunciado_adicional',
'opciones',
'respuesta_correcta',
'explicacion',
'imagenes_explicacion',
'nivel_dificultad',
'activo',
];
protected $casts = [
'opciones' => 'array',
'imagenes' => 'array',
'imagenes_explicacion' => 'array',
'activo' => 'boolean',
];
public function curso()
{
return $this->belongsTo(Curso::class);
}
public function scopeActivas($query)
{
return $query->where('activo', true);
}
public function scopeDeCurso($query, $cursoId)
{
return $query->where('curso_id', $cursoId);
}
public function scopeBuscar($query, $texto)
{
return $query->where(function ($q) use ($texto) {
$q->where('enunciado', 'like', "%{$texto}%")
->orWhere('enunciado_adicional', 'like', "%{$texto}%")
->orWhere('explicacion', 'like', "%{$texto}%");
});
}
}