outl1ne / nova-notes-field

This Laravel Nova package adds a notes field to Nova's arsenal of fields.
MIT License
51 stars 36 forks source link

Migrations and Model publishable #8

Closed newtongamajr closed 4 years ago

newtongamajr commented 4 years ago

I use several packages including multi-tenant. In the case of a multi-tenant its necessary to inform that the migrations will occur on the tenant-side or on the system-side. For models, I have to tell my model that the connection will occur to the tenant database or system database. If migrations and models are publishable, I can manage this problem and use your package, that's great! Also suggest, a config file to point for an alias for id columns, table names. model names and so on.

Thanks for your good job and I hope that my suggestions to be implemented for this package improvement!

Tarpsvo commented 4 years ago

Hi! I added migration(s) publishing in version 1.3.0. I also now allow the user to configure the table name.

Can you tell me what do you mean by model publishing? Do you really need to overwrite the model and the resource classes?

newtongamajr commented 4 years ago

Hi @Tarpsvo ! Yes, I need to modify Note model in order to add a Trait that indicates that this model uses a connection with another schema. What I think, that's the best way, is to create a new class inherited from Note, or transform the Note model content on a Trait, so we can use this trait on a brand new Note class, or even you can combine both. Since you use this model to access and maintain data, there's no need to publish Resource Class. Just add the $model = {model informed on config file or Note model by default}

Tarpsvo commented 4 years ago

Hey! Sorry for the delay.

I added an option to the config which allows you to provide your own Notes model.

Just create a new class that extends the class \OptimistDigital\NovaNotesField\Models\Note, add your own traits to it and then place it in the config as App\Models\CustomNote::class and it should work.

Good luck!

newtongamajr commented 4 years ago

Hi @Tarpsvo! Just to say thank's for your attention to solve my problem. Now everything is working really fine. An observation about your config option 'get_avatar_url' that became unnecessary now because extending the Note model, allowed me to overload the getCreatedByAvatarAttribute like this: public function getCreatedByAvatarUrlAttribute() { $createdBy = $this->createdBy; if (empty($createdBy)) return null; return $createdBy->url_avatar; }

And another thing about Note Model: $fillable is referencing 'model_id' and 'model_type' instead of 'notable_id' and 'notable_type'. As I'm extending this class, I could overload this too, but if someone is not doing that, will receive errors during record CRUD operations.