I have like this service provider where I try add custom Blueprint macros to use in migrations:
<?php
namespace My\Plugin\Providers;
use Winter\Storm\Support\ServiceProvider;
use Winter\Storm\Database\Schema\Blueprint;
class PluginServiceProvider extends ServiceProvider
{
public function register()
{
$this->registerBlueprintMacros();
}
/**
* Register the blueprint macros.
*/
protected function registerBlueprintMacros(): void
{
Blueprint::macro('productDates', function () {
$this->boolean('enabled')->default(false)->index();
$this->timestamp('starts_at')->nullable()->index();
$this->timestamp('ends_at')->nullable()->index();
});
}
}
Then I will register this service provider inside my Plugin.php file like this:
public function register()
{
// Register the service provider
$this->app->register(PluginServiceProvider::class);
}
Then when I try use registered columns in my migration:
Schema::create('plugin_products', function($table)
{
$table->engine = 'InnoDB';
$table->increments('id')->unsigned();
$table->string('title');
$table->text('description')->nullable();
// Usage example
$table->productDates();
});
Get error message:
Method
Winter\Storm\Database\Schema\Blueprint::productDatesdoes not exist.
How I can correctly register custom Blueprint macros in OctoberCMS & WinterCMS?