membuat tampilan untuk modul tiket
Untuk membuat modul tampilan tiket dalam Laravel, berikut adalah langkah-langkah yang dapat Anda ikuti:
Migrasi dan Model Tiket:
Gunakan perintah artisan untuk membuat migrasi tiket:
shell
Copy code
php artisan make:migration create_tickets_table --create=tickets
Buka file migrasi yang baru dibuat (misalnya database/migrations/2023_05_24_000000_create_tickets_table.php) dan tentukan skema kolom untuk tabel tiket. Contoh skema sederhana:
php
Copy code
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateTicketsTable extends Migration
{
public function up()
{
Schema::create('tickets', function (Blueprint $table) {
$table->id();
$table->string('subject');
$table->text('description');
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('tickets');
}
}
Jalankan migrasi untuk membuat tabel tiket:
shell
Copy code
php artisan migrate
Buat model Eloquent untuk tiket dengan perintah artisan:
shell
Copy code
php artisan make:model Ticket
Rute Tiket:
Buka file routes/web.php dan tambahkan rute untuk modul tiket:
php
Copy code
Route::get('/tickets', 'TicketController@index');
Route::get('/tickets/create', 'TicketController@create');
Route::post('/tickets', 'TicketController@store');
Route::get('/tickets/{ticket}', 'TicketController@show');
Controller Tiket:
Buat controller TicketController dengan perintah artisan:
shell
Copy code
php artisan make:controller TicketController
Di dalam TicketController, tambahkan metode berikut:
php
Copy code
<?php
namespace App\Http\Controllers;
use App\Models\Ticket;
use Illuminate\Http\Request;
class TicketController extends Controller
{
public function index()
{
$tickets = Ticket::all();
return view('tickets.index', compact('tickets'));
}
public function create()
{
return view('tickets.create');
}
public function store(Request $request)
{
$data = $request->validate([
'subject' => 'required|max:255',
'description' => 'required',
]);
Ticket::create($data);
return redirect('/tickets')->with('success', 'Tiket baru telah dibuat.');
}
public function show(Ticket $ticket)
{
return view('tickets.show', compact('ticket'));
}
}
View Tiket:
Buat view untuk menampilkan daftar tiket. Misalnya, buat file resources/views/tickets/index.blade.php dan tambahkan kode berikut:
html
Copy code
<!DOCTYPE html>
<html>
<head>
<title>Daftar Tiket</title>
</head>
<body>
<h1>Daftar Tiket</h1>
<a href="/tickets/create">Buat Tiket Baru</a>
<table>
<thead>
<tr>
<th>ID</th>
<th>Subjek</th>
<th>Tanggal Dibuat</th>
</tr>
</thead>