2017 © Pedro Peláez
 

library laravel-macroable-blueprint

Package to make the Blueprint macroable.

image

sebwas/laravel-macroable-blueprint

Package to make the Blueprint macroable.

  • Friday, September 8, 2017
  • by sebwas
  • Repository
  • 1 Watchers
  • 2 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

(obsolete) Laravel macroable blueprint

:boom: Warning! :boom: As of PR laravel/framework#19862 this package has become obsolete., (*1)

The Illuminate\Database\Schema\Blueprint class can do a lot. However, you might find yourself in a situation where you need a certain partial schema in your migrations over and over again. Unfortunately, the Blueprint class does not provide any one functionality to create reusable pieces these., (*2)

Installation

The installation is as simple as composer require sebwas/laravel-macroable-blueprint., (*3)

Usage

To use the macroable blueprint, you need to use the extending Schema from the package. That is, everywhere where you want to use the macros, you need to use SebWas\MacroableBlueprint\Schema instead of Illuminate\Facades\Schema., (*4)

To define the macros, simply call the macro method on the MacroableBlueprint class, like you're probably used to from other macroable classes from the bootstrap/app.php file. The callback is bound to the Blueprint class, thus can interact with it using $this (instead of the usual $table variable name)., (*5)

Example

In your bootstrap/app.php:, (*6)

// ...

SebWas\MacroableBlueprint\Blueprint::macro('social', function (array $providers, bool $bypassCheck = false) {
    if (!$bypassCheck) {
        $providers = array_intersect(
            ['google', 'facebook', 'bitbucket', 'github', 'twitter', 'linkedin'], // Valid providers
            $providers
        );
    }

    foreach ($providers as $provider) {
        $this->string("{$provider}_id")->nullable()->unique();
    }
});

// ...

In your migration file, e.g. database/migrations/2014_10_12_000000_create_users_table.php:, (*7)

<?php

use SebWas\MacroableBlueprint\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up() {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->social(['google', 'facebook']);
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down() {
        Schema::dropIfExists('users');
    }
}

Disclaimer

Please don't get upset about my coding style. It's called a style on purpose., (*8)

The Versions

08/09 2017

dev-master

9999999-dev

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires

 

04/05 2017

v5.4.6

5.4.6.0

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires

 

04/05 2017

v5.4.5

5.4.5.0

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires

 

04/05 2017

v5.4.4

5.4.4.0

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires

 

04/05 2017

v5.4.3

5.4.3.0

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires

 

04/05 2017

v5.4.2

5.4.2.0

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires

 

04/05 2017

v5.4.1

5.4.1.0

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires

 

04/05 2017

v5.4.0

5.4.0.0

Package to make the Blueprint macroable.

  Sources   Download

MIT

The Requires