feat: Establish one-to-many relationship between lecturers and courses, adding UI fields and table columns for assignment and display.
This commit is contained in:
parent
4cd80eae10
commit
0dac411fb0
@ -12,6 +12,7 @@
|
||||
use App\Models\Course;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
@ -80,6 +81,15 @@ public static function form(Schema $schema): Schema
|
||||
->maxValue(8)
|
||||
->helperText('Semester ke berapa mata kuliah ini diajarkan (1-8).'),
|
||||
|
||||
Select::make('lecturer_id')
|
||||
->label('Dosen Pengampu')
|
||||
->placeholder('Pilih Dosen')
|
||||
->relationship('lecturer', 'full_name')
|
||||
->preload()
|
||||
->searchable()
|
||||
->helperText('Pilih dosen yang mengampu mata kuliah ini.')
|
||||
->required(),
|
||||
|
||||
])
|
||||
->columns(1);
|
||||
}
|
||||
@ -101,6 +111,10 @@ public static function table(Table $table): Table
|
||||
->label('SKS')
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('lecturer.full_name')
|
||||
->label('Dosen Pengampu')
|
||||
->searchable(),
|
||||
|
||||
...TimestampColumns::make(),
|
||||
])
|
||||
->filters([
|
||||
|
||||
@ -3,9 +3,11 @@
|
||||
namespace App\Filament\Resources\Master\Lecturers\Schemas;
|
||||
|
||||
use App\Enums\Sex;
|
||||
use App\Models\Course;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Components\Grid;
|
||||
@ -115,6 +117,29 @@ public static function configure(Schema $schema): Schema
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
|
||||
Section::make('Mata Kuliah')
|
||||
->description('Daftar mata kuliah yang diampu oleh dosen ini.')
|
||||
->schema([
|
||||
Select::make('courses')
|
||||
->label('Mata Kuliah')
|
||||
->multiple()
|
||||
->relationship('courses', 'name')
|
||||
->options(function () {
|
||||
return Course::all()
|
||||
->groupBy('semester')
|
||||
->mapWithKeys(function ($courses, $semester) {
|
||||
return [
|
||||
"Semester $semester" => $courses->pluck('name', 'id')->toArray(),
|
||||
];
|
||||
})
|
||||
->toArray();
|
||||
})
|
||||
->searchable()
|
||||
->preload()
|
||||
->live()
|
||||
->required(),
|
||||
]),
|
||||
])
|
||||
->columns(1);
|
||||
}
|
||||
|
||||
@ -77,6 +77,12 @@ public static function configure(Table $table): Table
|
||||
->label('Alamat')
|
||||
->limit(50),
|
||||
|
||||
TextColumn::make('courses.name')
|
||||
->label('Mata Kuliah')
|
||||
->badge()
|
||||
->searchable()
|
||||
->listWithLineBreaks(),
|
||||
|
||||
...TimestampColumns::make(),
|
||||
])
|
||||
->filters([
|
||||
@ -85,6 +91,12 @@ public static function configure(Table $table): Table
|
||||
->options(Sex::class)
|
||||
->native(false),
|
||||
|
||||
SelectFilter::make('courses')
|
||||
->label('Mata Kuliah')
|
||||
->relationship('courses', 'name')
|
||||
->multiple()
|
||||
->preload(),
|
||||
|
||||
TrashedFilter::make()
|
||||
->native(false),
|
||||
])
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Course extends Model
|
||||
@ -11,4 +12,9 @@ class Course extends Model
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function lecturer(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Lecturer::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
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;
|
||||
|
||||
class Lecturer extends Model
|
||||
@ -40,4 +41,9 @@ public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function courses(): HasMany
|
||||
{
|
||||
return $this->hasMany(Course::class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ public function up(): void
|
||||
{
|
||||
Schema::create('courses', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('lecturer_id')->nullable()->constrained()->nullOnDelete();
|
||||
$table->string('code', 20)->unique();
|
||||
$table->string('name', 100);
|
||||
$table->integer('credit')->default(3);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user