refactor: remove direct association of lecturers with user accounts and related UI.

This commit is contained in:
Yoga Pangestu 2026-03-12 09:16:51 +07:00
parent 10f69a6914
commit dd8a313a24
7 changed files with 1 additions and 76 deletions

View File

@ -40,7 +40,7 @@ public function getSchedules()
->orWhereHas('students', fn ($asq) => $asq->where('students.id', $student->id));
});
})
->with(['course.lecturer.user', 'attendances' => function ($q) use ($student) {
->with(['course.lecturer', 'attendances' => function ($q) use ($student) {
$q->where('student_id', $student->id)
->whereDate('date', now()->toDateString());
}])

View File

@ -5,12 +5,8 @@
use App\Filament\Actions\BackAction;
use App\Filament\Resources\Master\Lecturers\LecturerResource;
use App\Filament\Support\SystemNotification;
use App\Models\User;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\CreateRecord;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
class CreateLecturer extends CreateRecord
{
@ -37,23 +33,4 @@ protected function getCreatedNotification(): ?Notification
{
return SystemNotification::create();
}
public function handleRecordCreation(array $data): Model
{
return DB::transaction(function () use ($data) {
$user = User::create([
'email' => $data['email'],
'username' => $data['username'],
'password' => Hash::make('Minimal8@'),
]);
unset($data['email'], $data['username']);
return $this->getResource()::getModel()::create(
array_merge($data, [
'user_id' => $user->id,
])
);
});
}
}

View File

@ -13,7 +13,6 @@
use Filament\Schemas\Components\Grid;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Illuminate\Support\HtmlString;
class LecturerForm
{
@ -21,30 +20,6 @@ public static function configure(Schema $schema): Schema
{
return $schema
->components([
Section::make('Akun')
->description(new HtmlString('Alamat Surel dan Nama Pengguna akan digunakan untuk masuk ke dalam sistem. Kata sandi bawaan adalah <code class="text-sm bg-gray-100 text-red-400 px-1.5 py-0.5 rounded font-mono">Minimal8@</code>'))
->schema([
TextInput::make('email')
->label('Alamat Surel')
->placeholder('johndoe@example.com')
->autocomplete(false)
->required()
->maxLength(254)
->email()
->unique('users', 'email', ignoreRecord: true),
TextInput::make('username')
->label('Nama Pengguna')
->placeholder('johndoe')
->autocomplete(false)
->required()
->minLength(5)
->maxLength(20)
->regex('/^[a-zA-Z0-9_.-]+$/')
->unique('users', 'username', ignoreRecord: true),
])
->columns(2)
->hiddenOn('edit'),
Section::make('Informasi Dosen')
->schema([

View File

@ -26,17 +26,6 @@ public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('user.email')
->label('Akun')
->formatStateUsing(fn ($state, Lecturer $record) => "
<div class='flex flex-col gap-1'>
<div><span class='font-bold text-gray-500 text-xs uppercase'>Alamat Surel:</span> <span class='font-medium'>{$state}</span></div>
<div><span class='font-bold text-gray-500 text-xs uppercase'>Nama Pengguna:</span> <span class='font-medium'>{$record->user?->username}</span></div>
</div>
")
->html()
->searchable(['email', 'username'])
->sortable(),
TextColumn::make('full_name')
->label('Nama Lengkap')

View File

@ -7,7 +7,6 @@
use Illuminate\Database\Eloquent\Builder;
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;
@ -37,11 +36,6 @@ protected function male(Builder $query): void
$query->where('sex', Sex::Male);
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function courses(): HasMany
{
return $this->hasMany(Course::class);

View File

@ -14,7 +14,6 @@ public function up(): void
{
Schema::create('lecturers', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->unique()->constrained()->cascadeOnDelete();
$table->string('lecturer_identification_number', 10)->unique();
$table->string('full_name', 100);
$table->string('phone_number', 20);

View File

@ -6,7 +6,6 @@
use Carbon\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
class LecturerSeeder extends Seeder
{
@ -49,15 +48,7 @@ public function run(): void
];
for ($i = 0; $i < 15; $i++) {
$userId = DB::table('users')->insertGetId([
'email' => 'dosen'.($i + 1).'@kampus.ac.id',
'username' => 'dosen'.($i + 1),
'password' => Hash::make('Minimal8@'),
]);
DB::table('lecturers')->insert([
'user_id' => $userId,
'lecturer_identification_number' => str_pad($i + 1, 10, '0', STR_PAD_LEFT),
'full_name' => $names[$i],
'phone_number' => '08123456'.rand(1000, 9999),