- Created SubmissionService to handle submission logic for assignments. - Added migrations for assignments and submissions tables. - Implemented AssignmentSeeder and SubmissionSeeder for initial data. - Updated DatabaseSeeder to include new seeders. - Enhanced app sidebar to include assignments navigation. - Developed datetime field component for better date and time input. - Created assignment management pages with data tables for assignments and submissions. - Implemented forms for creating and editing assignments and submissions. - Added routes for assignment and submission management in admin panel. - Defined types for assignments and submissions to improve type safety.
59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\SubmissionStatus;
|
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
|
|
#[Guarded(['id'])]
|
|
#[Appends(['file_url', 'file_name'])]
|
|
class Submission extends Model implements HasMedia
|
|
{
|
|
use HasFactory, InteractsWithMedia;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'status' => SubmissionStatus::class,
|
|
'submitted_at' => 'datetime',
|
|
'score' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function registerMediaCollections(): void
|
|
{
|
|
$this->addMediaCollection('submission_file')->singleFile();
|
|
}
|
|
|
|
public function assignment(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Assignment::class);
|
|
}
|
|
|
|
public function student(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Student::class);
|
|
}
|
|
|
|
protected function fileUrl(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->getFirstMediaUrl('submission_file') ?: null,
|
|
);
|
|
}
|
|
|
|
protected function fileName(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->getFirstMedia('submission_file')?->file_name,
|
|
);
|
|
}
|
|
}
|