Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ public function __construct()
public function up()
{
Schema::table($this->tableNames['quizzes'], function (Blueprint $table) {
$table->json('negative_marking_settings')->default(json_encode([
'enable_negative_marks' => true,
'negative_marking_type' => 'fixed',
'negative_mark_value' => 0,
]))->after('pass_marks');
$table->json('negative_marking_settings')->nullable()->after('pass_marks');
});
}

Expand Down
21 changes: 19 additions & 2 deletions src/Models/Quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace Harishdurga\LaravelQuiz\Models;

use Harishdurga\LaravelQuiz\Database\Factories\QuizFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Harishdurga\LaravelQuiz\Database\Factories\QuizFactory;

class Quiz extends Model
{
Expand Down Expand Up @@ -54,4 +55,20 @@ public function attempts()
{
return $this->hasMany(QuizAttempt::class);
}

/**
* Interact with the user's address.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
*/
protected function negativeMarkingSettings(): Attribute
{
return Attribute::make(
get: fn ($value) => empty($value) ? [
'enable_negative_marks' => true,
'negative_marking_type' => Quiz::FIXED_NEGATIVE_TYPE,
'negative_mark_value' => 0
] : json_decode($value, true),
);
}
}