@mdupor The decorator class needs to implement the same interface as the class you’re extending. The Blueprint doesn’t seem to implement an interface, so you can just delegate any unhandled methods to the underlying instance in your decorator class:
namespace App\Extensions\Database;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Traits;
class BlueprintExtension
{
use ForwardsCalls;
protected $blueprint;
public function __construct(Blueprint $blueprint)
{
$this->blueprint = $blueprint;
}
public function timestamps($precision = 0)
{
// Your timestamps implementation
}
public function __call($method, $parameters)
{
return $this->forwardCallTo($this->blueprint, $method, $parameters);
}
}
When extending a binding in the container, you’ll receive the original instance as the first parameter in the callback function:
$this->app->extend(Blueprint::class, function (Blueprint $blueprint) {
return new BlueprintDecorator($blueprint);
});
Now, whenever the Blueprint class is resolved by the container, your decorator class will be returned instead.