1
votes

I have a page that contains a dropdown whose contents(filters) are a result of a DB query and a table also populated with the results of a DB query. What i would like to do is to select one of the options of the dropdown and once selected, this option should be passed back on to the sql-query of the table as a variable so that the table can be displayed with these new filters.

Model1(Table):

  class TopPage {
       public static function webmasters(){
             $top_pages = DB::select(DB::raw('SELECT * 
                                     FROM my.top_pages
                 WHERE filter IS **Variable**
                                     LIMIT 10'));
             return $top_pages;

       }
  }

Model2(Dropdown):

  Class Dropdown {
        public static function getFilters() {
             $filter = DB::table('my.top_pages')->select(DB::raw('DISTINCT (filter) AS filt'))->lists('filt');
             return $filter;
        }
   }

Controller:

  class WebController extends BaseController {
        public function getSql_Test() {
                    $topPages = TopPage::webmasters();
                $filters = Dropdown::getFilters();
                        return View::make('tools.show',['TopPage'=>$topPages],
                      ['Dropdown'=>$filters]);

View:

  {{ Form::open() }}
    <p></p>
    <table class='liste' style='margin-left: 0px;' cellpadding='5'>
    {{ Form::select('filt', $Dropdown, 2) }}

    <p></p> 
    <tr>
           <td style='background-color: #426bb3; color: white; font-weight: bold; width:16%;'>Date</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%;'>Categorie</td>
    </tr>

        @foreach($TopPage as $topPages)
    <tr>
        <td> {{$topPages->date}} </td>              
        <td> {{$topPages->page}} </td>        
        <td> {{$topPages->categorie}} </td> 
    </tr>
    @endforeach 

        </table><br>  

   {{ Form::close() }}  

Any help would be greatly appreciated.

1

1 Answers

1
votes

Are you forgetting to include submit in view so it can call the filter?

{{ Form::submit('Search') }} 

In your form action you need to reference the function

Form::open(array('action' => 'Controller@method'))

Laravel Documentation

Laravel Documentation for HTML Forms