Reputation: 45
I want to make a filter based on request kelas
on database table. It gives me no error just when I click one of the filter, it don't show jadwal
page with my filter. It show the main page but the url is right like lps.com/?jadwal-2
I have done make a middleware called SanitizeMiddleware
from stackoverflow but still not worked.
This is my route web.php
Route::get('/', 'HomepageController@index');
Route::resource('pengumuman', 'PengumumanController');
Route::resource('jadwal', 'JadwalController');
Route::resource('rapot', 'RapotController');
This is my index() from my JadwalController
public function index()
{
if (request()->has('kelas')) {
$jadwal = jadwal::where('kelas', request('kelas'));
} else {
$jadwal = jadwal::all();
}
return view('jadwal.index')->with('jadwal',$jadwal);
//$jadwal = jadwal::all();
//return view('jadwal.index')->with('jadwal',$jadwal);
}
This is my index.blade.php
<div class="container">
<br>
<h1>
<strong>Jadwal Pelajaran</strong>
</h1>
<a href="/?kelas=1">jadwwal kelas 1</a>
<a href="/?kelas-2">jadwal kelas 2</a>
<a href="/?kelas-3">jadwal kelas 3</a>
</form>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">07.00-08.00</th>
<th scope="col">08.00-09.00</th>
<th scope="col">09.00-10.00</th>
<th scope="col">10.00-11.00</th>
<th scope="col">10.00-12.00</th>
<th scope="col">action</th>
</tr>
</thead>
<tbody>
@if(count($jadwal)>0)
@foreach($jadwal as $jadwals)
<tr>
<th scope="row">{{$jadwals->hari}}</th>
<td>{{$jadwals->jamke1}}</td>
<td>{{$jadwals->jamke2}}</td>
<td>{{$jadwals->jamke3}}</td>
<td>{{$jadwals->jamke4}}</td>
<td>{{$jadwals->jamke4}}</td>
<td>
<a href="/jadwal/{{$jadwals->id}}/edit" class="btn btn-info">Edit</a>
</td>
</tr>
@endforeach
@else
<p>tidak ada jadwal</p>
@endif
</tbody>
</table>
</div>
And this is the picture of problem:-
this is my jadwal page before filter
this my page after i click the filter using request()
Upvotes: 1
Views: 169
Reputation: 5180
HTML URL talking, lps.com/?jadwal-2
is just calling the home page with a GET parameter called jadwal-2
with no value at all. lps.com/jadwal
is good, lps.com/jadwal?kelas=2
is good. forget the dash
Using /
in href attribute tell the system to start from the the top level path. Change to relative like :
<a href="?kelas=1">jadwwal kelas 1</a>
<a href="?kelas-2">jadwal kelas 2</a>
<a href="?kelas-3">jadwal kelas 3</a>
So being on page lps.com/jadwal
will result in url lps.com/jadwal?kelas=1
which is the correct syntax and pattern.
Upvotes: 0
Reputation: 6351
its just a simple url issue
as you see the list of jadwal is displayed in the route
lps.com/jadwal
What is the issue as you see
<a href="/?kelas=1">jadwwal kelas 1</a>
<a href="/?kelas=2">jadwal kelas 2</a>
<a href="/?kelas=3">jadwal kelas 3</a>
While Clicking this any of the link its redirecting to
For Example If i Clicked jadwwal kelas 1
lps.com/?kelas=1
So Its not redireting to lps.com/jadwal?kelas=1
So Try to change
<a href="jadwal/?kelas=1">jadwwal kelas 1</a>
<a href="jadwal/?kelas=2">jadwal kelas 2</a>
<a href="jadwal/?kelas=3">jadwal kelas 3</a>
And the final thing if you are using the pagination
{{$jadwal->links()}}
This Will only add the ?page=yourCurrentPageNumber
But in Some situation You need both the filters and pagination
So Try below Method
{{$jadwal->appends(request()->input())->links()}}
It will appends all the GET
Request Parameter
So If You need to vist the nth page
of kelas=1
its will work
Hope its helps
if you are facing and issue kindly comment below
Upvotes: 2