Create View in MySQL through Laravel

5

How can I create a view in the MySQL database through migrations of Laravel? I did not find anything in the documentation.

    
asked by anonymous 26.09.2016 / 19:35

1 answer

4

There is a feasible way to create Views with Database Migrations , but it's a forma textual :

Command: DB::statement , instead of Schema::create

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class Creditosativos extends Migration
{
    public function up()
    {
        DB::statement("CREATE VIEW v_creditos_ativos AS
                        SELECT * from creditos where status = 1");
    }
    public function down()
    {
        DB::statement("DROP VIEW v_creditos_ativos");
    }
}

Reference:

26.09.2016 / 21:18