title: How to create slugs in Laravel?
body: <p>I'm trying to develop an e-com website in Laravel 5 (Since it required lot of customization, I decided not to use Magento or OpenCart).</p>
  
  <p>The problem I'm facing is to creating category and product URLs from slugs.</p>
  
  <p>For example, one URL can be:</p>
  
  <p><a href="http://somewebsite.com/products/lenovo-yoga-500" rel="nofollow noreferrer">http://somewebsite.com/products/lenovo-yoga-500</a></p>
  
  <p>But I want to make URL like:</p>
  
  <p><a href="http://somewebsite.com/lenovo-yoga-500" rel="nofollow noreferrer">http://somewebsite.com/lenovo-yoga-500</a></p>
  
  <p>I tried to create a route like:</p>
  
  <pre><code>Route::get('{slug}', 'BaseController@route');
  </code></pre>
  
  <p>and in the route() method, I tried:</p>
  
  <pre><code>function route($route){
      $product = Product::where(array('slug' =&gt; $slug))-&gt;first();
  
      if(isset($product))
      .....
      else
      .....
  </code></pre>
  
  <p>but first of all, the value is not getting passed to variable '$slug' and secondly I want to redirect the request to another route after checking the condition.</p>