How to Extend BluePrint?
I want to add seeds to migrations inline with column adds. I have a supplemental table that tells my solution additional information about a table field. I want to extend the create function for features like this:
$table->string('name')->bgfields('foo','bar');
I tried modifying my migrations table to call my Diesel Blueprint class instead of the standard via:
//use Illuminate\Database\Schema\Blueprint; use App\Diesel\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')->unique(); $table->string('name')->bgfields('foo','bar'); }); }...
Then setup my own class:
namespace App\Diesel; use Illuminate\Database\Schema\Blueprint; use DB;
class Blueprint extends Illuminate\Database\Schema\Blueprint { public function bgfields($bgfields_descript = '', $bgfields_type= '', $bgfield_internal = 0) {
DB::table('bgfields')->insert(array(
[
'bgfields_descript' => $bgfields_descript,
'bgfields_type' => $bgfields_type,
'bgfield_internal' => $bgfield_internal
]));
return $this;
}
}
When run, I get:
[ErrorException]
Argument 1 passed to CreateUsersTable::{closure}() must be an instance of App\Diesel\Blueprint, instance of Illuminate\Database\Schema\Blueprint given, called in Users/Dayveian/git/diesel/vendor/laravel/framework/src/Illuminate/Database/Schema/Builder.php on line 132 and defined
I believe this is because my closure function in the migration table wants the diesel object, but the callback is in blueprint. I do not know how to get around this problem. Any suggestions or my hopes to extend won't work and I should try something else?
Thanks,
Please or to participate in this conversation.