title: How to use laravel Eloquent model in helper class
body: <p>How do I use a laravel Eloquent model outside of a controller? I cannot seem to find out what <code>use "*insert class here*"</code> statement I should use. I have a helper class that will be using my "Category model" often. </p>
  
  <p>Here is the code I am using. It is failing when i use Category:</p>
  
  <pre><code>&lt;?php
  
  namespace Msh\Redirects;
  
  use Illuminate\Support\Facades\Config as Config;
  use Illuminate\Support\Facades\Input as Input;
  
  
  /**
   * This is the actual "product class" that generates the 301 redirect url's
   *
   * This is the product
   *
   * @author bgarrison
   */
  class StorefrontRedirectsGenerator implements RedirectsGenerator {
  
      public function generateUrls() {
          // Set the database to the name of the domain
          Config::set('database.connections.mysql_tenant.database', Input::get('domain'));
  
          // Grab all the categories
          $categories = Category::all();
  
          // Use category information to determine request url's and target url's
          $urlMapping = [];
          $count = 0;
          $categoryCount = 0;
          foreach ($categories as $category) {
              if ($category-&gt;Published == 1) {
                  $oldUrl = 'c-' . $category-&gt;CategoryID . '-' . $category-&gt;SEName . '.aspx';
                  $urlMapping['category_urls'][$oldUrl][] = $category-&gt;SEName . '.html';
                  $count++;
                  $categoryCount++;
              }
              if ($category-&gt;ParentCategoryID !== '0') {
                  $parentCategory = Category::where('CategoryID', '=', (int) $category-&gt;ParentCategoryID)-&gt;get();
                  foreach ($parentCategory as $pcategory) {
                      $url = $pcategory-&gt;SEName . '/' . $urlMapping['category_urls'][$oldUrl][0];
                      if (!in_array($url, $urlMapping['category_urls'][$oldUrl])) {
                          $urlMapping['category_urls'][$oldUrl][] = $url;
                          $count++;
                          $categoryCount++;
                      }
                  }
              }
          }
          $urlMapping['category_urls']['count'] = $categoryCount;
          return Response::json([
                  'success' =&gt; true,
                  'count' =&gt; $count,
                  'data' =&gt; $urlMapping
          ]);
      }
  
  }
  </code></pre>