engelsystem/src/Models/Question.php

83 lines
1.8 KiB
PHP
Raw Normal View History

2019-12-03 20:09:37 +01:00
<?php
declare(strict_types=1);
namespace Engelsystem\Models;
2019-10-31 15:18:27 +01:00
use Carbon\Carbon;
2019-12-03 20:09:37 +01:00
use Engelsystem\Models\User\User;
use Engelsystem\Models\User\UsesUserModel;
use Illuminate\Database\Eloquent\Builder;
2021-07-10 00:59:20 +02:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2019-12-03 20:09:37 +01:00
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Query\Builder as QueryBuilder;
2019-12-03 20:09:37 +01:00
/**
2019-10-31 15:18:27 +01:00
* @property int $id
* @property string $text
* @property string $answer
* @property int $answerer_id
* @property Carbon|null $answered_at
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*
* @property-read User $answerer
*
2019-12-03 20:09:37 +01:00
* @method static Builder|Question whereAnswer($value)
* @method static Builder|Question whereAnswererId($value)
* @method static Builder|Question whereId($value)
* @method static Builder|Question whereQuestion($value)
*/
class Question extends BaseModel
{
2021-07-10 00:59:20 +02:00
use HasFactory;
2019-12-03 20:09:37 +01:00
use UsesUserModel;
2019-10-31 15:18:27 +01:00
/** @var bool Enable timestamps */
public $timestamps = true;
/** @var string[] */
protected $dates = [
'answered_at'
];
2019-12-03 20:09:37 +01:00
/** @var string[] */
protected $fillable = [
'user_id',
'text',
'answerer_id',
'answer',
2019-10-31 15:18:27 +01:00
'answered_at',
2019-12-03 20:09:37 +01:00
];
/** @var string[] */
protected $casts = [
'user_id' => 'integer',
'answerer_id' => 'integer',
];
/**
* @return BelongsTo
*/
public function answerer(): BelongsTo
{
return $this->belongsTo(User::class, 'answerer_id');
}
/**
* @return Builder
*/
public static function unanswered(): Builder
{
return static::whereAnswererId(null);
}
/**
* @return Builder|QueryBuilder
2019-12-03 20:09:37 +01:00
*/
public static function answered(): Builder
{
return static::whereNotNull('answerer_id');
}
}