2021-08-10 12:09:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use App\Enums\QuestionType;
|
2023-10-06 15:00:42 +02:00
|
|
|
use App\Traits\Models\ActivityLog;
|
2021-08-10 12:09:49 +02:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
2023-09-06 17:24:53 +02:00
|
|
|
/**
|
|
|
|
|
* @property integer $id Id.
|
|
|
|
|
* @property integer $brand_id Foreign key Brand.
|
|
|
|
|
* @property string $question Question.
|
|
|
|
|
* @property \App\Enums\QuestionType $type Type de question.
|
|
|
|
|
* @property-read \Illuminate\Support\Carbon $created_at Created date.
|
|
|
|
|
* @property-read \Illuminate\Support\Carbon $updated_at Updated date.
|
|
|
|
|
*
|
2025-04-17 11:32:43 +02:00
|
|
|
* @property-read \Illuminate\Support\Collection $answers Answer hasMany relation.
|
|
|
|
|
* @property-read \App\Models\Brand $brand Brand BelongsTo relation.
|
2023-09-06 17:24:53 +02:00
|
|
|
*/
|
2021-08-10 12:09:49 +02:00
|
|
|
class Question extends Model
|
|
|
|
|
{
|
2023-10-06 15:00:42 +02:00
|
|
|
use ActivityLog;
|
2021-08-10 12:09:49 +02:00
|
|
|
use HasFactory;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
|
*
|
2025-07-24 11:32:12 +02:00
|
|
|
* @var array<int, string>
|
2021-12-19 15:57:24 +01:00
|
|
|
*/
|
2021-08-10 12:09:49 +02:00
|
|
|
protected $fillable = [
|
|
|
|
|
'question',
|
2022-12-01 17:35:21 +01:00
|
|
|
'type',
|
2023-09-04 13:08:34 +02:00
|
|
|
'brand_id',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Map attribute names to enum classes.
|
|
|
|
|
*
|
2025-07-24 11:32:12 +02:00
|
|
|
* @var array<string, mixed>
|
2023-09-04 13:08:34 +02:00
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'type' => QuestionType::class,
|
2021-08-10 12:09:49 +02:00
|
|
|
];
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
// * RELATIONS
|
|
|
|
|
|
2021-08-10 12:09:49 +02:00
|
|
|
/**
|
2025-07-24 11:32:12 +02:00
|
|
|
* Brand belongs to relation.
|
2021-08-10 12:09:49 +02:00
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function brand(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
2021-08-10 12:09:49 +02:00
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Brand::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2025-07-24 11:32:12 +02:00
|
|
|
* Answer has many relation.
|
2021-08-10 12:09:49 +02:00
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function answers(): \Illuminate\Database\Eloquent\Relations\HasMany
|
2021-08-10 12:09:49 +02:00
|
|
|
{
|
|
|
|
|
return $this->hasMany(Answer::class);
|
|
|
|
|
}
|
|
|
|
|
}
|