I want to override the timestamps()
function found in the Blueprint
class. How can I do that?
e.g.,
public function up() { Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('username')->unique(); $table->string('password'); $table->string('email'); $table->string('name'); $table->timestamps(); // <-- I want this to call my method instead of the one found in the base Blueprint class }); }
Using the Add New ButtonIn the Content Browser, click the Add New button. Select Blueprint Class from the Create Basic Asset section of the dropdown menu. You can create several different types of Blueprint Assets from the Blueprints option under Create Advanced Asset. Choose a Parent Class for your Blueprint Asset.
Definition: A class is a blueprint that defines the variables and the methods common to all objects of a certain kind.
C++ classes can be extended with Blueprints, allowing programmers to set up new gameplay classes in code that can be built upon and changed with Blueprints by level designers.
Blueprint is an open-source tool for rapidly generating multiple Laravel components from a single, human-readable definition. Blueprint works by using a draft file (YAML) that contains definitions of the components it should generate.
There is a new blueprintResolver
function which takes a callback function which then returns the Blueprint
instance.
So create your custom Blueprint class like this:
class CustomBlueprint extends Illuminate\Database\Schema\Blueprint{ public function timestamps() { //Your custom timestamp code. Any output is not shown on the console so don't expect anything } }
And then call the blueprintResolver
function where you return your CustomBlueprint
instance.
public function up() { $schema = DB::connection()->getSchemaBuilder(); $schema->blueprintResolver(function($table, $callback) { return new CustomBlueprint($table, $callback); }); $schema->create('users', function($table) { //Call your custom functions }); }
I'm not sure if creating a new schema instance with DB::connection()->getSchemaBuilder();
is state of the art but it works.
You could additionally override the Schema
facade and add the custom blueprint by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With