title: Filter with dropdown Laravel
body: <p>I have a dropdown that I´m using to filter images by category. My first problem is that I want the selected choice to be selected after the filter, how can I do that?</p>
  
  <p>This is my first time using Laravel and I wonder if I´m going in the right direction with my solution (now I have the same code in two functions, I´m planning on fixing that), but I can´t really figure out the best way of doing this. Can I have a function that takes either a category or null?</p>
  
  <pre><code>     &lt;div class="dropdown"&gt;
          &lt;button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" value=""&gt;Show all&lt;/button&gt;
          &lt;ul class="dropdown-menu" role="menu"&gt;
              @foreach ($categories as $category)
                 &lt;li value="{{ $category-&gt;id }}"&gt;&lt;a href="{{$category-&gt;id}}"&gt;{{ $category-&gt;name }}&lt;/a&gt;&lt;/li&gt;
              @endforeach
          &lt;/ul&gt;
       &lt;/div&gt;
  </code></pre>
  
  <p>routes</p>
  
  <pre><code>Route::get('/', array('uses' =&gt; 'MyController@index'));
  Route::get('/{category?}', array('uses' =&gt; 'MyController@filter'));
  </code></pre>
  
  <p>controller</p>
  
  <pre><code>public function index()
  {
      $images = Image::all();
  
      $categories = ..\Models\Category::all();
  
      return View::make('index', array('images' =&gt; $images, 'categories' =&gt; $categories));
  }
  
  public function filter($category){
  
      $images = Image::where('category_id', '=', $category);
  
      $categories = ..\Models\Category::all();
  
      return View::make('index', array('images' =&gt; $images, 'categories' =&gt; $categories));
  
  }
  </code></pre>