1. Buka file FormController, Kemudian dibagian index()
ubah script tersebut seperti dibawah :
public function index()
{
$siswas = Siswa::orderBy('created_at', 'DESC')->get();
return view('index', compact('siswas'));
}
2. Buat file index.php pada folder resources/views lkemudian isikan kode dibawah ini.
@extends('layout')
@section('content')
<h1 style="text-align: center">Daftar Data Siswa </h1>
@if(session()->has('message'))
<p>{{ session()->get('message') }}</p>
@endif
<a href="{{ route('form.create') }}">Tambah Data</a>
<table width="100%" cellpading="0" cellspacing="0">
<thead>
<tr>
<th width="10%">No</th>
<th align="left" width="30%">NIS</th>
<th align="left" width="30%">Nama</th>
<th width="30%">Tindakan</th>
</tr>
</thead>
<tbody>
@if($siswas->count())
@php($index = 1)
@foreach($siswas as $siswa)
<tr>
<td align="center">{{ $index++ }}</td>
<td>{{ $siswa->nis }}</td>
<td>{{ $siswa->nama }}</td>
<td align="center">
<a href="{{ route('form.edit', $siswa->id) }}">Edit</a> | <a onclick="document.getElementById('hapus-{{ $siswa->id }}').submit()" style="color: #ff0000; cursor: pointer;">Hapus</a>
<form action="{{ route('form.destroy', $siswa->id) }}" id="hapus-{{ $siswa->id }}" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="delete">
</form>
</td>
</tr>
@endforeach
@else
<tr>
<td align="center" colspan="4">Data tidak tersedia</td>
</tr>
@endif
</tbody>
</table>
@endsection
Buka browser lalu ketik http://127.0.0.1:8000/form maka akan ditampilkan gambar dibawah ini