Skip to content

Commit

Permalink
Enhancement Pendaftaran
Browse files Browse the repository at this point in the history
  • Loading branch information
Noisycools committed Sep 22, 2023
2 parents 84294ae + 85c5988 commit f2d1bf6
Show file tree
Hide file tree
Showing 7 changed files with 372 additions and 265 deletions.
38 changes: 35 additions & 3 deletions app/Http/Controllers/PendaftaranController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

use Illuminate\Http\Request;
use App\Models\FakultasJurusan;
use App\Models\Mahasiswa;
use App\Models\Pendaftaran;
use App\Models\ProgramStudi;
use Illuminate\Support\Facades\DB;

class PendaftaranController extends Controller
{
Expand All @@ -20,10 +23,12 @@ public function index()

public function formPendaftaranMahasiswa()
{
$email = auth()->user()->email;
$data = [
'title' => 'Form Pendaftaran Mahasiswa',
'fakultasJurusan' => FakultasJurusan::all(),
'programStudi' => ProgramStudi::all(),
'cekDaftar' => DB::table('mahasiswa')->where('email', $email)->count(),
];

return view('pages.mahasiswa.pendaftaran', $data);
Expand All @@ -48,23 +53,50 @@ public function create()
public function store(Request $request)
{
$dataToValidate = [
'name' => 'required',
'nama' => 'required',
'email' => 'required|unique:mahasiswa',
'alamat' => 'required',
'telepon' => 'required',
'jenis_kelamin' => 'required',
'tanggal_lahir' => 'required|date',
'file_ijazah' => 'required|file|max:2000|mimes:pdf',
'file_kk' => 'required|file|max:2000|mimes:pdf',
'file_pasfoto' => 'required|image|file|max:1024|mimes:jpg',
'file_butawarna' => 'file|max:2000|mimes:pdf',
'fakultas_jurusan' => 'required',
'program_studi' => 'required',
'program_studi_id' => 'required',
];

if ($request->email != auth()->user()->email)
$dataToValidate['email'] = 'required|unique:users|unique:mahasiswa';

$validatedData = $request->validate($dataToValidate);

if ($request->file('file_ijazah')) {
$validatedData['file_ijazah'] = $request->file('file_ijazah')->store('ijazah');
}

if ($request->file('file_kk')) {
$validatedData['file_kk'] = $request->file('file_kk')->store('kartu_keluarga');
}

if ($request->file('file_pasfoto')) {
$validatedData['file_pasfoto'] = $request->file('file_pasfoto')->store('pas_foto');
}

if ($request->file('file_butawarna')) {
$validatedData['file_butawarna'] = $request->file('file_butawarna')->store('surat_butawarna');
}

$insertMahasiswa = Mahasiswa::create($validatedData);
Pendaftaran::create([
'mahasiswa_id' => $insertMahasiswa->id,
'tanggal_pendaftaran' => now(),
'status' => 'Proses',
'created_at' => now(),
'updated_at' => now(),
]);

return redirect()->route('formPendaftaranMahasiswa')->with('success', 'Anda telah melakukan pendaftaran! Silahkan lakukan proses pembayaran pada halaman berikut.');
}

/**
Expand Down
24 changes: 24 additions & 0 deletions app/Models/Mahasiswa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Mahasiswa extends Model
{
use HasFactory;

protected $table = 'mahasiswa';
protected $guarded = ['id'];

public function programStudi()
{
return $this->belongsTo(ProgramStudi::class);
}

public function pendaftaran()
{
return $this->hasMany(Pendaftaran::class);
}
}
20 changes: 20 additions & 0 deletions app/Models/Pendaftaran.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Pendaftaran extends Model
{
use HasFactory;

protected $table = 'pendaftaran';
protected $guarded = ['id'];


public function mahasiswa()
{
return $this->belongsTo(Mahasiswa::class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up()
Schema::create('mahasiswa', function (Blueprint $table) {
$table->id();
$table->string('nama');
$table->string('nim')->unique();
$table->string('nim')->unique()->nullable();
$table->string('alamat');
$table->string('email')->unique();
$table->enum('jenis_kelamin', ['Laki-laki', 'Perempuan']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function up()
$table->unsignedBigInteger('mahasiswa_id');
$table->date('tanggal_pendaftaran');
$table->enum('status', ['Diterima', 'Ditolak', 'Proses']);
$table->text('data_pendaftaran'); // Kolom ini bisa berisi berkas pendaftaran atau data lainnya
$table->text('keterangan')->nullable(); // Kolom ini opsional
$table->timestamps();
});
Expand Down
32 changes: 16 additions & 16 deletions public/assets/js/mahasiswa/pendaftaran.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,44 @@ $(document).ready(function () {
$("#file_ijazah").bind("change", function () {
var filename = $("#file_ijazah").val();
if (/^\s*$/.test(filename)) {
$(".file-upload").removeClass("active");
$("#noFile").text("No file chosen...");
$(".ijazah").removeClass("active");
$("#noFile-ijazah").text("No file chosen...");
} else {
$(".file-upload").addClass("active");
$("#noFile").text(filename.replace("C:\\fakepath\\", ""));
$(".ijazah").addClass("active");
$("#noFile-ijazah").text(filename.replace("C:\\fakepath\\", ""));
}
});

$("#file_kk").bind("change", function () {
var filename = $("#file_kk").val();
if (/^\s*$/.test(filename)) {
$(".file-upload").removeClass("active");
$("#noFile").text("No file chosen...");
$(".kk").removeClass("active");
$("#noFile-kk").text("No file chosen...");
} else {
$(".file-upload").addClass("active");
$("#noFile").text(filename.replace("C:\\fakepath\\", ""));
$(".kk").addClass("active");
$("#noFile-kk").text(filename.replace("C:\\fakepath\\", ""));
}
});

$("#file_pasfoto").bind("change", function () {
var filename = $("#file_pasfoto").val();
if (/^\s*$/.test(filename)) {
$(".file-upload").removeClass("active");
$("#noFile").text("No file chosen...");
$(".pasfoto").removeClass("active");
$("#noFile-pasfoto").text("No file chosen...");
} else {
$(".file-upload").addClass("active");
$("#noFile").text(filename.replace("C:\\fakepath\\", ""));
$(".pasfoto").addClass("active");
$("#noFile-pasfoto").text(filename.replace("C:\\fakepath\\", ""));
}
});

$("#file_butawarna").bind("change", function () {
var filename = $("#file_butawarna").val();
if (/^\s*$/.test(filename)) {
$(".file-upload").removeClass("active");
$("#noFile").text("No file chosen...");
$(".butawarna").removeClass("active");
$("#noFile-butawarna").text("No file chosen...");
} else {
$(".file-upload").addClass("active");
$("#noFile").text(filename.replace("C:\\fakepath\\", ""));
$(".butawarna").addClass("active");
$("#noFile-butawarna").text(filename.replace("C:\\fakepath\\", ""));
}
});
});
Loading

0 comments on commit f2d1bf6

Please sign in to comment.