How can I create a view
in the MySQL database through migrations
of Laravel? I did not find anything in the documentation.
How can I create a view
in the MySQL database through migrations
of Laravel? I did not find anything in the documentation.
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: