File manager - Edit - /home/autoph/public_html/projects/aha-api/app/Models/SurveyAnswer.php
Back
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use OwenIt\Auditing\Contracts\Auditable; use Illuminate\Database\Eloquent\SoftDeletes; use OwenIt\Auditing\Auditable as AuditableTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; class SurveyAnswer extends Model implements Auditable { use HasFactory, SoftDeletes, AuditableTrait; /** * The attributes that are NOT mass assignable. * */ protected $guarded = ['deleted_at']; /** * The attributes that should be cast. * * @var array<string, string> */ protected $casts = []; protected $appends = ['question_content']; /** * The entry the answer belongs to. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function entry() { return $this->belongsTo(SurveyEntry::class); } /** * The question the answer belongs to. * * @return \Illuminate\Database\Eloquent\Relations\BelongsTo */ public function question() { return $this->belongsTo(SurveyQuestion::class); } public function getQuestionContentAttribute() { return SurveyQuestion::withTrashed()->find($this->question_id)->content; } public static function getRatingsByQuestionId($id) { return \DB::table('survey_answers AS answers') ->selectRaw(" SUM(CASE WHEN answers.value = '1' THEN 1 ELSE 0 END) AS rating1, SUM(CASE WHEN answers.value = '2' THEN 1 ELSE 0 END) AS rating2, SUM(CASE WHEN answers.value = '3' THEN 1 ELSE 0 END) AS rating3, SUM(CASE WHEN answers.value = '4' THEN 1 ELSE 0 END) AS rating4, SUM(CASE WHEN answers.value = '5' THEN 1 ELSE 0 END) AS rating5 ") ->leftJoin('survey_questions AS questions', 'answers.question_id', '=', 'questions.id') ->leftJoin('survey_entries AS entries', 'answers.entry_id', '=', 'entries.id') ->where('questions.id', $id) ->whereNull('entries.deleted_at') ->groupBy('questions.id') ->get(); } }
| ver. 1.4 |
.
| PHP 8.1.32 | Generation time: 0.03 |
proxy
|
phpinfo
|
Settings