This repository has been archived on 2021-01-24. You can view files and clone it, but cannot push or open issues or pull requests.
laravel-elearning/app/Option.php

42 lines
906 B
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Option extends Model
{
public function question()
{
return $this->belongsTo(Question::class);
}
public function deleteOption()
{
$this->delete();
return true;
}
public function addOption($question, $optionData)
{
$this->option = $optionData["option"];
if (array_key_exists("correct_answer", $optionData)) {
$this->correct_answer = 1;
} else {
$this->correct_answer = 0;
}
$question->options()->save($this);
}
public function updateOption($optionData)
{
$this->option = $optionData["option"];
if (array_key_exists("correct_answer", $optionData)) {
$this->correct_answer = 1;
} else {
$this->correct_answer = 0;
}
$this->update();
}
}