mein-sterntours/app/Models/AnswerQuestion.php
2025-04-01 10:40:14 +02:00

96 lines
3.5 KiB
PHP

<?php
/**
* Created by Reliese Model.
*/
namespace App\Models;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
/**
* Class AnswerQuestion
*
* @property int $id
* @property string $question
* @property string $question_text
* @property string $answer
* @property string $answer_text
* @property bool $active
* @property Carbon $created_at
* @property Carbon $updated_at
* @package App\Models
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereAnswer($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereAnswerText($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereQuestion($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereQuestionText($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\IQContentFaq[] $iq_content_faq
* @property-read int|null $iq_content_faq_count
* @property int|null $i_q_content_category_id
* @property-read \App\Models\IQContentCategory|null $iq_content_category
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\AnswerQuestion whereIQContentCategoryId($value)
* @mixin \Eloquent
*/
class AnswerQuestion extends Model
{
protected $connection = 'mysql_stern';
protected $table = 'answer_questions';
protected $casts = [
'active' => 'bool'
];
protected $fillable = [
'i_q_content_category_id',
'question',
'question_text',
'answer',
'answer_text',
'active'
];
public function iq_content_category()
{
return $this->belongsTo(IQContentCategory::class, 'i_q_content_category_id');
}
public function iq_content_faq()
{
return $this->hasMany(IQContentFaq::class, 'faq_id', 'id');
}
public static function getSiteOptions($id, $identifier, $html = true, $choose = true) {
$values = [];
$ret = "";
$models = AnswerQuestion::with('iq_content_category')->select('answer_questions.*')->where('answer_questions.active', 1)//->where('iq_content_category.identifier', $identifier)
->whereHas('iq_content_category', function ($q) use ($identifier) {
$q->where('slug', 'reisefuehrer');
})->get();
if($html) {
if($choose){
$ret .= '<option value="">Bitte wählen</option>\n';
}
foreach ($models as $model) {
$attr = ($model->id == $id) ? ' selected="selected"' : '';
$ret .= '<option value="' . $model->id . '"' . $attr . '>' . $model->question . '</option>\n';
}
return $ret;
}else{
foreach ($models as $model) {
$values[$model->id] = $model->question;
}
return $values;
}
return false;
}
}