Eduardo Trujillo

Found a quick way of avoiding using the Schema facade for migrations in Laravel:

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

namespace App\Database;

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Query\Builder;

/**
 * Class BaseMigration
 *
 * Base migration class
 *
 * @package App\Database
 */
abstract class BaseMigration extends Migration
{
    /**
     * @var Builder
     */
    protected $builder;

    /**
     * Construct an instance of a BaseMigration
     */
    public function __construct()
    {
        $this->builder = app('db')
            ->connection($this->connection)
            ->getSchemaBuilder();
    }
}

Why? This should help with the type hinting provided by some IDEs such as PHPStorm.

To use this class, extend it from every migration you make and replace any mention of Schema:: with just $this->builder->


Alternative Formats
This post is also available in Markdown: View source