I have a Form that contains a Dropdown and a Submit button. Like so:
View path: webmasters/filters.blade.php
{{ Form::open() }}
{{ Form::select('filt', $Dropdown, 2) }}
{{ Form::Submit('Filter') }}
{{ Form::close() }}
And a controller that populates the Dropdown with values queried from a DB. Like so:
Controller name: WebController.php
class WebController extends BaseController {
public function getFilters() {
$filters = Dropdown::getFilters();
return View::make('webmasters.filter',['Dropdown'=>$filters]);
}
public function postFilters() {
$filt = Input::get('name'); // getting the value of the select
$filters = Dropdown::getFilters();
$query = DB::table('webmasters.top_pages')->where('filter',$filt)->limit(20)->get();
return View::make('webmasters.filter', array('query'=>$query),['Dropdown'=>$filters]);
}
}
Here is my route:
Route::resource('topPage', 'WebController@getFilters');
getFilters is a model method that queries the DB for the values that come into the dropdown.
EDIT
My View file:
{{ Form::open() }}
<p></p>
<table class='liste' style='margin-left: 0px;' cellpadding='5'>
{{ Form::select('name', $Dropdown) }}
<div>
{{ Form::Submit('Filter') }}
</div>
<tr>
<td style='background-color: #426bb3; color: white; font-weight: bold; width:16%;'>Datum</td>
<td align='left' style='background-color: #426bb3; color: white; font-weight: bold; width:12%;'>Page</td>
<td align='left' style='background-color: #426bb3; color: white; font-weight: bold; width:12%;'>Kategorie</td>
</tr>
@foreach($Webmasters as $topPages)
<tr>
<td> {{$topPages->date}} </td>
<td> {{$topPages->page}} </td>
<td> {{$topPages->category}} </td>
</tr>
@endforeach
</table><br>
{{ Form::close() }}
I would like to call a controller method upon submitting the form so that the said method queries another DB and returns a table (on the same page as the dropdown and submit button) based on the selected value of the dropdown.
Since the default Form created using Form::post() is using POST, i figured i could access the value of the select using the second method in my controller postFilters(). This method goes ahead and uses the value as a where-clause as it queries anther DB and passes the results onto a View. The Problem is, the View is not loading. I suppose i'm doing something wrong on the routing?? Can someone help?
filters.blade.php? Or at least the part of it where the table should be displayed... - lukasgeiter