-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
323 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
// app/Http/Controllers/NotesController.php | ||
|
||
use App\Models\Note; | ||
use Illuminate\Http\Request; | ||
use App\Models\Kelas; | ||
|
||
class NoteController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$notes = Note::all(); // Mengambil semua data catatan dari database | ||
|
||
return view('notes.index', [ | ||
'title' => 'Catatan Kuliah', | ||
'notes' => $notes, // Meneruskan data catatan ke tampilan | ||
]); | ||
} | ||
|
||
|
||
|
||
public function store(Request $request) | ||
{ | ||
// Validasi data input dari form | ||
$validatedData = $request->validate([ | ||
'judul' => 'required', | ||
'isi' => 'required', | ||
'kelas_id' => 'required', | ||
]); | ||
|
||
// Simpan catatan baru ke database | ||
Note::create($validatedData); | ||
|
||
return redirect('/notes')->with('success', 'Catatan berhasil ditambahkan.'); | ||
} | ||
|
||
public function create() | ||
{ | ||
$kelas = Kelas::all(); // Mengambil data mata kuliah (kelas) dari tabel kelas | ||
|
||
return view('notes.create', [ | ||
'title' => 'Tambah Catatan Baru', | ||
'kelas' => $kelas, // Meneruskan data mata kuliah ke tampilan create | ||
]); | ||
|
||
} | ||
|
||
|
||
|
||
public function edit(Note $note) | ||
{ | ||
// Ambil data kelas yang diperlukan | ||
$kelas = Note::all(); // Gantilah dengan metode yang sesuai untuk mengambil data kelas | ||
|
||
return view('notes.edit', compact('note', 'kelas')); | ||
} | ||
|
||
|
||
public function update(Request $request, Note $note) | ||
{ | ||
$validatedData = $request->validate([ | ||
'judul' => 'required', | ||
'isi' => 'required', | ||
'kelas_id' => 'required', | ||
]); | ||
|
||
$note->update($validatedData); | ||
|
||
return redirect('/notes')->with('success', 'Catatan berhasil diperbarui.'); | ||
} | ||
|
||
public function destroy(Note $note) | ||
{ | ||
$note->delete(); | ||
return redirect('/notes')->with('success', 'Catatan berhasil dihapus.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use App\Models\Kelas; | ||
|
||
|
||
class Note extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $table = 'notes'; | ||
|
||
protected $fillable = ["judul", "isi", "kelas_id"]; | ||
|
||
public function kelas() | ||
{ | ||
return $this->belongsTo(Kelas::class); | ||
} | ||
|
||
public $timestamps = false; | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
database/migrations/2023_10_21_112320_create_notes_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateNotesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('notes', function (Blueprint $table) { | ||
$table->id(); | ||
$table->unsignedBigInteger('kelas_id'); | ||
$table->string('judul'); | ||
$table->text('isi'); | ||
|
||
$table->foreign('kelas_id')->references('id')->on('kelas')->onDelete('cascade'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('notes'); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
@extends('layouts.main') | ||
|
||
@section('container') | ||
<div class="container"> | ||
<h1>Tambah Catatan</h1> | ||
<form action="{{ route('notes.store') }}" method="POST" enctype="multipart/form-data"> | ||
@csrf | ||
|
||
<div class="form-group"> | ||
<label for="judul" class="form-label">Judul</label> | ||
<input type="text" class="form-control" id="judul" name="judul" required> | ||
</div> | ||
<div class="form-group"> | ||
<label for="isi" class="form-label">Isi</label> | ||
<textarea class="form-control" id="isi" name="isi" rows="5" required></textarea> | ||
</div> | ||
<div class="form-group"> | ||
<label for="kelas_id" class="form-label">Mata Kuliah</label> | ||
<select class="form-select" id="kelas_id" name="kelas_id" required> | ||
@if (!empty($kelas) && is_array($kelas)) | ||
@if (count($kelas) > 0) | ||
@foreach ($kelas as $kelasItem) | ||
<option value="{{ $kelasItem->id }}">{{ $kelasItem->matkul }}</option> | ||
@endforeach | ||
@else | ||
<option value="">Pilih Mata Kuliah</option> | ||
@endif | ||
@else | ||
<option value="">Pilih Mata Kuliah</option> | ||
<p>Tidak ada data kelas yang tersedia.</p> | ||
@endif | ||
</select> | ||
</div> | ||
|
||
<button type="submit" class="btn btn-primary mt-3">Simpan</button> | ||
</form> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@extends('layouts.main') | ||
|
||
@section('container') | ||
<h1>Edit Catatan</h1> | ||
|
||
<form action="{{ route('notes.update', $note) }}" method="POST"> | ||
@csrf | ||
@method('PUT') | ||
<div class="mb-3"> | ||
<label for="judul" class="form-label">Judul</label> | ||
<input type="text" class="form-control" id="judul" name="judul" value="{{ $note->judul }}" required> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="isi" class="form-label">Isi</label> | ||
<textarea class="form-control" id="isi" name="isi" rows="5" required>{{ $note->isi }}</textarea> | ||
</div> | ||
<div class="mb-3"> | ||
<label for="kelas_id" class="form-label">Mata Kuliah</label> | ||
<select class="form-select" id="kelas_id" name="kelas_id" required> | ||
@foreach ($kelas as $kelas) | ||
<option value="{{ $kelas->id }}" @if($note->kelas_id == $kelas->id) selected @endif>{{ $kelas->matkul }}</option> | ||
@endforeach | ||
</select> | ||
</div> | ||
<button type="submit" class="btn btn-primary">Simpan Perubahan</button> | ||
</form> | ||
@endsection |
Oops, something went wrong.