orbit icon indicating copy to clipboard operation
orbit copied to clipboard

Add ability to create dynamic schema for Model

Open phuclh opened this issue 3 years ago • 4 comments

Make Orbit able to create schema outside the model class.

Orbit::registerDynamicSchema('posts', function (Blueprint $table) {
    $table->string('external_url')->nullable();
});

This will add external_url column to the posts table.

phuclh avatar Apr 16 '22 23:04 phuclh

@phuclh How exactly would you use this?

ryangjchandler avatar Apr 17 '22 09:04 ryangjchandler

@ryangjchandler My use case is I have a blog platform and some users want to write their plugins for the blog. One of the plugins requires adding new columns to the Post model. Of course, they cannot add it in the schema method in the Post model since it lives in the core. That was why I came up with this PR.

phuclh avatar Apr 18 '22 05:04 phuclh

Hi @ryangjchandler, do you think you can merge this PR? Thank you!

phuclh avatar Apr 30 '22 18:04 phuclh

@phuclh I feel like a nicer API might be registering the custom schema on the model itself, no? Something like Post::registerDynamicSchema()?

ryangjchandler avatar May 01 '22 11:05 ryangjchandler