HoshiAI-be/app/Models/Test.php
2025-11-13 22:40:22 +01:00

48 lines
860 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Test extends Model
{
use HasFactory;
protected $fillable = [
'title',
'description',
'category_id',
'author_id',
'closed_at',
];
protected $dates = [
'closed_at',
'created_at',
'updated_at',
];
public function isAvailable()
{
return $this->closed_at === null || now()->lt($this->closed_at);
}
public function category()
{
return $this->belongsTo(Category::class);
}
public function author()
{
return $this->belongsTo(User::class);
}
public function questions()
{
return $this->belongsToMany(Question::class)
->withTimestamps();
}
}