db rework

This commit is contained in:
RetasyaSalsabila 2026-02-06 21:20:28 +07:00
parent 875ce92cd2
commit aaddeafaae
41 changed files with 842 additions and 379 deletions

View File

@ -13,20 +13,33 @@ public function showLoginForm()
return view('auth.login-admin');
}
public function login(Request $request)
{
$credentials = $request->only('username', 'password');
public function loginAdmin(Request $request)
{
$request->validate([
'username' => 'required',
'password' => 'required',
]);
if (Auth::guard('admin')->attempt($credentials, $request->filled('remember'))) {
return redirect()->intended(route('admin.dashboard'));
$credentials = $request->only('username', 'password');
if (Auth::guard('admin')->attempt($credentials)) {
$request->session()->regenerate();
return redirect()->intended(route('admin.dashboard'));
}
return back()->withErrors([
'username' => 'Username atau password salah'
])->withInput($request->except('password'));
}
return back()->withErrors(['username' => 'Username atau password salah']);
}
public function logout()
public function logout(Request $request)
{
Auth::guard('admin')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect()->route('admin.login');
}
}

View File

@ -4,20 +4,36 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Admin extends Authenticatable
{
use HasFactory, Notifiable;
use Notifiable;
protected $table = 'admins';
protected $primaryKey = 'id_admin';
public $incrementing = true;
protected $keyType = 'string';
protected $fillable = [
'nama',
'username',
'password',
'password'
];
protected $hidden = [
'password',
'remember_token',
];
public function getAuthIdentifierName()
{
return 'id_admin';
}
public function getAuthIdentifier()
{
return $this->getKey();
}
}

22
app/Models/Badge.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Badge extends Model
{
use HasFactory;
protected $table = 'badges';
protected $primaryKey = 'id_badge';
protected $fillable = [
'nama_badge',
'deskripsi',
'icon_badge',
'syarat',
];
}

View File

@ -1,11 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Challenge extends Model {
protected $guarded = [];
public function kelas(){ return $this->belongsTo(Kelas::class); }
public function guru(){ return $this->belongsTo(Guru::class); }
public function scores(){ return $this->hasMany(Score::class); }
}
class Challenge extends Model
{
use HasFactory;
protected $table = 'challenges';
protected $primaryKey = 'id_challenge';
protected $fillable = [
'id_admin',
'judul_challenge',
'deskripsi',
'exp',
'id_badge',
'tenggat_waktu',
];
}

View File

@ -1,9 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Guru extends Model {
protected $guarded = [];
public function challenges(){ return $this->hasMany(Challenge::class); }
class Guru extends Model
{
protected $table = 'guru'; // INI PENTING!
protected $primaryKey = 'nip';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'nip',
'nama',
'email',
'password'
];
}

View File

@ -1,10 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Kelas extends Model {
protected $guarded = [];
public function siswas(){ return $this->hasMany(Siswa::class); }
public function challenges(){ return $this->hasMany(Challenge::class); }
}
class Kelas extends Model
{
use HasFactory;
protected $table = 'kelas';
protected $primaryKey = 'id_kelas';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'id_kelas',
'nama_kelas',
'tingkat',
];
}

View File

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Leaderboard extends Model
{
use HasFactory;
protected $table = 'leaderboards';
protected $primaryKey = 'id_history';
protected $fillable = [
'nisn',
'id_kelas',
'total_exp',
'ranking',
'semester',
'tahun_ajaran',
'tanggal_snapshot',
];
}

View File

@ -9,6 +9,14 @@ class Mapel extends Model
{
use HasFactory;
protected $table = 'mapels';
protected $fillable = ['nama'];
}
protected $table = 'mapels';
protected $primaryKey = 'id_mapel';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'id_mapel',
'nama_mapel',
];
}

22
app/Models/Materi.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Materi extends Model
{
use HasFactory;
protected $table = 'materis';
protected $primaryKey = 'id_materi';
protected $fillable = [
'id_mengajar',
'judul_materi',
'lampiran_materi',
'deskripsi',
'tanggal_upload',
];
}

21
app/Models/Mengajar.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Mengajar extends Model
{
use HasFactory;
protected $table = 'mengajars';
protected $primaryKey = 'id_mengajar';
protected $fillable = [
'nip',
'id_mapel',
'id_kelas',
];
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PengumpulanTugas extends Model
{
use HasFactory;
protected $table = 'pengumpulan_tugas';
protected $primaryKey = 'id_pengumpulan';
protected $fillable = [
'id_tugas',
'nisn',
'lampiran_tugas',
'tanggal_submit',
'exp',
'status',
];
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PesertaChallenge extends Model
{
use HasFactory;
protected $table = 'peserta_challenges';
protected $primaryKey = 'id_peserta';
protected $fillable = [
'id_challenge',
'nisn',
'jawaban',
'waktu_submit',
'exp',
'status',
];
}

View File

@ -1,10 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Siswa extends Model {
protected $guarded = [];
public function kelas(){ return $this->belongsTo(Kelas::class); }
public function scores(){ return $this->hasMany(Score::class); }
}
class Siswa extends Model
{
use HasFactory;
protected $table = 'siswas';
protected $primaryKey = 'nisn';
public $incrementing = false;
protected $keyType = 'string';
protected $fillable = [
'nisn',
'password',
'nama',
'tempat_lahir',
'tanggal_lahir',
'id_kelas',
];
protected $hidden = [
'password',
];
}

21
app/Models/SiswaBadge.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class SiswaBadge extends Model
{
use HasFactory;
protected $table = 'siswa_badges';
protected $primaryKey = 'id_siswa_badge';
protected $fillable = [
'nisn',
'id_badge',
'tanggal_diberikan',
];
}

21
app/Models/Tugas.php Normal file
View File

@ -0,0 +1,21 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Tugas extends Model
{
use HasFactory;
protected $table = 'tugas';
protected $primaryKey = 'id_tugas';
protected $fillable = [
'id_mengajar',
'judul_tugas',
'keterangan',
'deadline',
];
}

View File

@ -38,19 +38,19 @@
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
'provider' => 'user',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
'provider' => 'admin',
],
'guru' => [
'driver' => 'session',
'provider' => 'gurus',
'provider' => 'guru',
],
'siswa' => [
'driver' => 'session',
'provider' => 'siswas',
'provider' => 'siswa',
],
],
@ -73,19 +73,19 @@
*/
'providers' => [
'users' => [
'user' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
'admins' => [
'admin' => [
'driver' => 'eloquent',
'model' => App\Models\Admin::class,
],
'gurus' => [
'guru' => [
'driver' => 'eloquent',
'model' => App\Models\Guru::class,
],
'siswas' => [
'siswa' => [
'driver' => 'eloquent',
'model' => App\Models\Siswa::class,
],

View File

@ -1,57 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('jobs', function (Blueprint $table) {
$table->id();
$table->string('queue')->index();
$table->longText('payload');
$table->unsignedTinyInteger('attempts');
$table->unsignedInteger('reserved_at')->nullable();
$table->unsignedInteger('available_at');
$table->unsignedInteger('created_at');
});
Schema::create('job_batches', function (Blueprint $table) {
$table->string('id')->primary();
$table->string('name');
$table->integer('total_jobs');
$table->integer('pending_jobs');
$table->integer('failed_jobs');
$table->longText('failed_job_ids');
$table->mediumText('options')->nullable();
$table->integer('cancelled_at')->nullable();
$table->integer('created_at');
$table->integer('finished_at')->nullable();
});
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('jobs');
Schema::dropIfExists('job_batches');
Schema::dropIfExists('failed_jobs');
}
};

View File

@ -1,30 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->text('content');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('posts');
}
};

View File

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('siswas', function (Blueprint $table) {
$table->id();
$table->string('nama');
$table->string('nis')->nullable();
$table->foreignId('kelas_id')->constrained('kelas')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('siswas');
}
};

View File

@ -1,45 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('challenges', function (Blueprint $table) {
$table->id();
$table->string('judul_challenge');
$table->text('deskripsi')->nullable();
$table->date('tenggat_waktu')->nullable();
$table->integer('exp_poin')->default(0);
// Relasi ke guru yang membuat challenge
$table->foreignId('guru_id')->constrained('gurus')->onDelete('cascade');
// Relasi ke admin yang menyetujui challenge (optional)
$table->foreignId('admin_id')->nullable()->constrained('admins')->onDelete('set null');
// Relasi ke kelas (challenge ini untuk kelas mana)
$table->foreignId('kelas_id')->nullable()->constrained('kelas')->onDelete('set null');
// Status challenge
$table->enum('status', ['draft', 'pending', 'approved', 'rejected'])->default('pending');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('challenges');
}
};

View File

@ -1,31 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::create('scores', function (Blueprint $table) {
$table->id();
$table->foreignId('siswa_id')->constrained('siswas')->onDelete('cascade');
$table->foreignId('challenge_id')->constrained('challenges')->onDelete('cascade');
$table->integer('score')->default(0);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('scores');
}
};

View File

@ -1,21 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration {
public function up(): void
{
Schema::table('admins', function (Blueprint $table) {
$table->rememberToken()->after('password');
});
}
public function down(): void
{
Schema::table('admins', function (Blueprint $table) {
$table->dropColumn('remember_token');
});
}
};

View File

@ -10,21 +10,16 @@
* Run the migrations.
*/
public function up(): void
{
Schema::create('admins', function (Blueprint $table) {
$table->id();
$table->string('username')->unique();
$table->string('password');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
{
Schema::create('admins', function (Blueprint $table) {
$table->id('id_admin')->primary();
$table->string('username', 50)->unique();
$table->string('password');
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('admins');
}
};
};

View File

@ -9,15 +9,15 @@
/**
* Run the migrations.
*/
public function up()
{
Schema::create('kelas', function (Blueprint $table) {
$table->id();
$table->string('nama');
$table->timestamps();
});
}
public function up(): void
{
Schema::create('kelas', function (Blueprint $table) {
$table->string('id_kelas', 20)->primary();
$table->string('nama_kelas', 50);
$table->enum('tingkat', ['X', 'XI', 'XII']);
$table->timestamps();
});
}
/**
* Reverse the migrations.
@ -26,4 +26,4 @@ public function down(): void
{
Schema::dropIfExists('kelas');
}
};
};

View File

@ -9,16 +9,15 @@
/**
* Run the migrations.
*/
public function up()
{
Schema::create('gurus', function (Blueprint $table) {
$table->id();
$table->string('nama');
$table->string('nip')->nullable();
$table->timestamps();
});
}
public function up(): void
{
Schema::create('gurus', function (Blueprint $table) {
$table->string('nip', 30)->primary();
$table->string('password');
$table->string('nama', 100);
$table->timestamps();
});
}
/**
* Reverse the migrations.
@ -27,4 +26,4 @@ public function down(): void
{
Schema::dropIfExists('gurus');
}
};
};

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('siswas', function (Blueprint $table) {
$table->string('nisn', 20)->primary();
$table->string('password');
$table->string('nama', 100);
$table->string('tempat_lahir', 50);
$table->date('tanggal_lahir');
$table->string('id_kelas', 20);
$table->timestamps();
$table->foreign('id_kelas')
->references('id_kelas')
->on('kelas')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('siswas');
}
};

View File

@ -9,14 +9,14 @@
/**
* Run the migrations.
*/
public function up()
{
Schema::create('mapels', function (Blueprint $table) {
$table->id();
$table->string('nama');
$table->timestamps();
});
}
public function up(): void
{
Schema::create('mapels', function (Blueprint $table) {
$table->string('id_mapel', 20)->primary();
$table->string('nama_mapel', 100);
$table->timestamps();
});
}
/**
* Reverse the migrations.
@ -25,4 +25,4 @@ public function down(): void
{
Schema::dropIfExists('mapels');
}
};
};

View File

@ -0,0 +1,45 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('mengajars', function (Blueprint $table) {
$table->id('id_mengajar');
$table->string('nip', 30);
$table->string('id_mapel', 20);
$table->string('id_kelas', 20);
$table->timestamps();
$table->foreign('nip')
->references('nip')
->on('gurus')
->onDelete('cascade');
$table->foreign('id_mapel')
->references('id_mapel')
->on('mapels')
->onDelete('cascade');
$table->foreign('id_kelas')
->references('id_kelas')
->on('kelas')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('mengajars');
}
};

View File

@ -0,0 +1,37 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('materis', function (Blueprint $table) {
$table->id('id_materi');
$table->unsignedBigInteger('id_mengajar');
$table->string('judul_materi', 200);
$table->string('lampiran_materi')->nullable();
$table->text('deskripsi')->nullable();
$table->timestamp('tanggal_upload')->useCurrent();
$table->timestamps();
$table->foreign('id_mengajar')
->references('id_mengajar')
->on('mengajars')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('materis');
}
};

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('tugas', function (Blueprint $table) {
$table->id('id_tugas');
$table->unsignedBigInteger('id_mengajar');
$table->string('judul_tugas', 200);
$table->text('keterangan')->nullable();
$table->datetime('deadline');
$table->timestamps();
$table->foreign('id_mengajar')
->references('id_mengajar')
->on('mengajars')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('tugas');
}
};

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('pengumpulan_tugas', function (Blueprint $table) {
$table->id('id_pengumpulan');
$table->unsignedBigInteger('id_tugas');
$table->string('nisn', 20);
$table->string('lampiran_tugas')->nullable();
$table->datetime('tanggal_submit');
$table->integer('exp')->default(0);
$table->enum('status', ['dikumpulkan', 'terlambat', 'belum'])->default('belum');
$table->timestamps();
$table->foreign('id_tugas')
->references('id_tugas')
->on('tugas')
->onDelete('cascade');
$table->foreign('nisn')
->references('nisn')
->on('siswas')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('pengumpulan_tugas');
}
};

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('badges', function (Blueprint $table) {
$table->id('id_badge');
$table->string('nama_badge', 100);
$table->text('deskripsi')->nullable();
$table->string('icon_badge')->nullable();
$table->text('syarat');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('badges');
}
};

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('challenges', function (Blueprint $table) {
$table->id('id_challenge');
$table->unsignedBigInteger('id_admin');
$table->string('judul_challenge', 200);
$table->text('deskripsi')->nullable();
$table->integer('exp')->default(0);
$table->unsignedBigInteger('id_badge')->nullable();
$table->datetime('tenggat_waktu');
$table->timestamps();
$table->foreign('id_admin')
->references('id_admin')
->on('admins')
->onDelete('cascade');
$table->foreign('id_badge')
->references('id_badge')
->on('badges')
->onDelete('set null');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('challenges');
}
};

View File

@ -0,0 +1,43 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('peserta_challenges', function (Blueprint $table) {
$table->id('id_peserta');
$table->unsignedBigInteger('id_challenge');
$table->string('nisn', 20);
$table->text('jawaban')->nullable();
$table->datetime('waktu_submit')->nullable();
$table->integer('exp')->default(0);
$table->enum('status', ['selesai', 'belum'])->default('belum');
$table->timestamps();
$table->foreign('id_challenge')
->references('id_challenge')
->on('challenges')
->onDelete('cascade');
$table->foreign('nisn')
->references('nisn')
->on('siswas')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('peserta_challenges');
}
};

View File

@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('siswa_badges', function (Blueprint $table) {
$table->id('id_siswa_badge');
$table->string('nisn', 20);
$table->unsignedBigInteger('id_badge');
$table->timestamp('tanggal_diberikan')->useCurrent();
$table->timestamps();
$table->foreign('nisn')
->references('nisn')
->on('siswas')
->onDelete('cascade');
$table->foreign('id_badge')
->references('id_badge')
->on('badges')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('siswa_badges');
}
};

View File

@ -0,0 +1,44 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('leaderboards', function (Blueprint $table) {
$table->id('id_history');
$table->string('nisn', 20);
$table->string('id_kelas', 20);
$table->integer('total_exp')->default(0);
$table->integer('ranking');
$table->string('semester', 50);
$table->string('tahun_ajaran', 20);
$table->timestamp('tanggal_snapshot')->useCurrent();
$table->timestamps();
$table->foreign('nisn')
->references('nisn')
->on('siswas')
->onDelete('cascade');
$table->foreign('id_kelas')
->references('id_kelas')
->on('kelas')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('leaderboards');
}
};

View File

@ -11,22 +11,6 @@
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
Schema::create('sessions', function (Blueprint $table) {
$table->string('id')->primary();
$table->foreignId('user_id')->nullable()->index();
@ -42,8 +26,6 @@ public function up(): void
*/
public function down(): void
{
Schema::dropIfExists('users');
Schema::dropIfExists('password_reset_tokens');
Schema::dropIfExists('sessions');
}
};

View File

@ -9,14 +9,13 @@
class AdminSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Admin::create([
'id_admin' => '101',
'username' => 'chaca',
'password' => Hash::make('admin123'),
]);
}
}
}

View File

@ -8,19 +8,14 @@
class DatabaseSeeder extends Seeder
{
use WithoutModelEvents;
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
$this->call(AdminSeeder::class);
// User::factory()->create([
// 'name' => 'Test User',
// 'email' => 'test@example.com',
// ]);
// Panggil AdminSeeder
$this->call([
AdminSeeder::class,
]);
}
}

View File

@ -6,8 +6,6 @@
<div class="text-center mt-5">
<h1 class="fw-bold text-primary mb-4">Selamat Datang di Website Kami</h1>
<p class="mb-4">Ini halaman landing sederhana. Silakan pilih login sesuai role kamu.</p>
<a href="{{ route('admin.login') }}" class="btn btn-primary">Login Admin</a>
<a href="{{ route('login.guru') }}" class="btn btn-primary">Login Guru</a>
<a href="{{ route('login.siswa') }}" class="btn btn-primary">Login Siswa</a>
<a href="{{ route('admin.login') }}" class="btn btn-primary">Login Admin</a>
</div>
@endsection

View File

@ -3,8 +3,10 @@
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Admin\LoginController;
use App\Http\Controllers\Admin\AdminController;
use App\Http\Controllers\GuruController;
use App\Http\Controllers\SiswaController;
use App\Http\Controllers\KelasController;
@ -18,79 +20,112 @@
Route::get('/', function () {
return view('auth.landing-page');
})->name('landing-page');
// ====================
// LOGIN ROUTES (VIEW)
// ====================
Route::prefix('admin')->group(function () {
// Halaman login (GET)
Route::get('/login', [LoginController::class, 'showLoginForm'])->name('admin.login');
// Proses login (POST)
Route::post('/login', [LoginController::class, 'login'])->name('admin.login.submit');
// Dashboard admin (GET)
Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard')->middleware('auth:admin');
// Logout admin
Route::post('/logout', [LoginController::class, 'logout'])->name('admin.logout');
});
Route::get('/login/guru', [LoginController::class, 'showLoginForm'])->name('login.guru');
Route::get('/login/siswa', [LoginController::class, 'showLoginForm'])->name('login.siswa');
// ====================
// LOGIN PROSES
// ====================
Route::post('/admin/login', [LoginController::class, 'login'])->name('admin.login.submit');
// =======================================================
// LOGIN PAGES (VIEW ONLY)
// =======================================================
// Guru login
// Selector login (opsional)
Route::get('/login', function () {
return view('auth.login-selector');
})->name('login.selector');
// LOGIN ADMIN
Route::get('/admin/login', function () {
return view('auth.login-admin');
})->name('admin.login');
// LOGIN GURU
Route::get('/guru/login', function () {
return view('auth.login-guru');
})->name('guru.login');
// LOGIN SISWA
Route::get('/siswa/login', function () {
return view('auth.login-siswa');
})->name('siswa.login');
// =======================================================
// PROSES LOGIN (POST)
// =======================================================
// ADMIN LOGIN PROCESS
Route::post('/admin/login', [LoginController::class, 'loginAdmin'])
->name('admin.login.submit');
// GURU LOGIN PROCESS
Route::post('/guru/login', function (Request $request) {
$credentials = $request->only('nip', 'password');
if (Auth::guard('guru')->attempt($credentials)) {
return redirect()->route('guru.dashboard');
}
return back()->withErrors(['nip' => 'NIP atau password salah']);
})->name('guru.login.submit');
// Siswa login
// SISWA LOGIN PROCESS
Route::post('/siswa/login', function (Request $request) {
$credentials = $request->only('nisn', 'password');
if (Auth::guard('siswa')->attempt($credentials)) {
return redirect()->route('siswa.dashboard');
}
return back()->withErrors(['nisn' => 'NISN atau password salah']);
})->name('siswa.login.submit');
// ====================
// ADMIN AREA
// ====================
// =======================================================
// ADMIN AREA (HARUS LOGIN ADMIN)
// =======================================================
Route::middleware(['auth:admin'])->prefix('admin')->name('admin.')->group(function () {
Route::get('/admin/notif', function () {
return view('admin.notif');
})->name('admin.notif');
Route::get('/admin/profil', function () {
return view('admin.profil');
})->name('admin.profil');
Route::get('/dashboard', [AdminController::class, 'dashboard'])->name('dashboard');
Route::get('/notif', function () {
return view('admin.notif');
})->name('notif');
Route::get('/profil', function () {
return view('admin.profil');
})->name('profil');
// CRUD AREA
Route::resource('guru', GuruController::class);
Route::resource('siswa', SiswaController::class);
Route::resource('kelas', KelasController::class);
Route::resource('mapel', MapelController::class);
Route::resource('challenge', ChallengeController::class);
Route::get('leaderboard', [LeaderboardController::class, 'index'])->name('leaderboard.index');
Route::post('/logout', [LoginController::class, 'logout'])->name('logout');
Route::get('leaderboard', [LeaderboardController::class, 'index'])
->name('leaderboard.index');
// LOGOUT ADMIN
Route::post('/logout', [LoginController::class, 'logout'])
->name('logout');
});
// =======================================================
// GURU AREA
// =======================================================
Route::middleware(['auth:guru'])->group(function () {
Route::get('/guru/dashboard', function () {
return view('guru.dashboard');
})->name('guru.dashboard');
});
Route::get('/guru/dashboard', fn() => view('guru.dashboard'))->name('guru.dashboard');
Route::get('/siswa/dashboard', fn() => view('siswa.dashboard'))->name('siswa.dashboard');
require __DIR__.'/auth.php';
// =======================================================
// SISWA AREA
// =======================================================
Route::middleware(['auth:siswa'])->group(function () {
Route::get('/siswa/dashboard', function () {
return view('siswa.dashboard');
})->name('siswa.dashboard');
});