title: How to create the migrations for database views using php artisan in Laravel?
body: <p>Actually, I have managed to create a sql views for Laravel using PHP Artisan using below step.</p>
  
  <p>Step 1. Run below command:</p>
  
  <pre><code>php artisan make:migration create_overall_report_views
  </code></pre>
  
  <p>Step 2.</p>
  
  <p>Open the migration file and add the below code:</p>
  
  <pre><code>class CreateOverallReportView extends Migration 
  {
    /**
    * Run the migrations.
    *
    * @return void
    */
    public function up()
    {
      //
      DB::statement("
        CREATE VIEW views_overall_report AS
        (
          SELECT er.user_id as user_id, e.id AS entities_id, 
              c.status_id AS status_id, s.name AS status_name
  
          FROM `user_roles` er
            LEFT JOIN elists e ON e.id=er.entities_id
            LEFT JOIN `clists` c ON c.id=e.checklists_id
            LEFT JOIN `status` s ON s.id = c.overall_status_id
  
          WHERE s.slug = 'completed'
            AND c.deleted_at IS NULL
        )
      ");
    }
  
    /**
    * Reverse the migrations.
    *
    * @return void
    */
    public function down()
    {
      DB::statement('DROP VIEW IF EXISTS views_overall_report');
    }  
  
  }
  </code></pre>
  
  <p>Step 3. To call and run the SQL Views via Laravel query</p>
  
  <pre><code>$items = $DB::table('views_overall_report')
              -&gt;select('status_id', 'status_name',
                  $DB::raw('count(entities_id) as counts')
              )
              -&gt;groupBy('status_id')
              -&gt;orderBy('counts' , 'desc')
              -&gt;whereIn('user_id', Auth::user()-&gt;id())
              -&gt;get();
  print_r($items);
  </code></pre>
  
  <p>Hope that helps. Please let me know if anyone has better solution!!</p>