Snapshot of main at 9f39a6e1e (2026-11-02)
This commit is contained in:
commit
6ccf1792d7
2580 files changed
+1040202
No files matched your search
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Polls\Contracts\QuestionType;
|
||||
use App\Polls\Localized;
|
||||
use App\Polls\QuestionTypeRegistry;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class PollQuestion extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['poll_id', 'position', 'type', 'label', 'settings', 'required'];
|
||||
|
||||
protected $casts = [
|
||||
'label' => 'array',
|
||||
'settings' => 'array',
|
||||
'required' => 'boolean',
|
||||
];
|
||||
|
||||
|
||||
public function poll()
|
||||
{
|
||||
return $this->belongsTo(Poll::class);
|
||||
}
|
||||
|
||||
public function answers()
|
||||
{
|
||||
return $this->hasMany(PollAnswer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Label in the given (or current) locale, falling back to the app fallback locale
|
||||
* and then to the first label that is filled in.
|
||||
*/
|
||||
public function labelFor(?string $locale = null): string
|
||||
{
|
||||
return Localized::pick($this->label, $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* The question type handling this question.
|
||||
*/
|
||||
public function questionType(): QuestionType
|
||||
{
|
||||
return app(QuestionTypeRegistry::class)->get($this->type);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user