- 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.
58 lines
1.5 KiB
PHP
58 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
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 Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\MediaLibrary\HasMedia;
|
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
|
|
|
#[Guarded(['id'])]
|
|
#[Appends(['attachment_url', 'attachment_name'])]
|
|
class Assignment extends Model implements HasMedia
|
|
{
|
|
use HasFactory, InteractsWithMedia, SoftDeletes;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'deadline' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function registerMediaCollections(): void
|
|
{
|
|
$this->addMediaCollection('assignment_attachment')->singleFile();
|
|
}
|
|
|
|
public function courseClass(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CourseClass::class);
|
|
}
|
|
|
|
public function submissions(): HasMany
|
|
{
|
|
return $this->hasMany(Submission::class);
|
|
}
|
|
|
|
protected function attachmentUrl(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->getFirstMediaUrl('assignment_attachment') ?: null,
|
|
);
|
|
}
|
|
|
|
protected function attachmentName(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->getFirstMedia('assignment_attachment')?->file_name,
|
|
);
|
|
}
|
|
}
|