Xethron / migrations-generator

Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.
MIT License
3.33k stars 585 forks source link

Detection of timestamps & softDeletes #143

Open phpguru opened 7 years ago

phpguru commented 7 years ago

This library has saved so much time. The only way this helpful library could be better, IMO, is if you detect created_at, updated_at you include public $timestamps = true; in the generated model, and similarly, if you detect deleted_at you inject use softDeletes into the class. If there's a config or CLI flag to achieve this optionally, even better. I'd use it. Just filing this here. I can probably craft a PR for it.

phpguru commented 7 years ago

The only other thing I do is I remove created_at, updated_at and deleted_at from every $fillable = [ ... ] array the generator creates. I believe it is desirable to not actually have these be fillable, since Laravel takes care of it automatically when public $timestamps = true; and use softDeletes; are present. I think it's arguably fine to leave this in, though, since those fields could be "your schema" and not actually a part of softDeletes & $timestamps.

cacpmw commented 5 years ago

@phpguru how is it possible to generate the model with this lib? I thought it only generated migration files

phpguru commented 5 years ago

@cacpmw I said “model” I meant migration. My comment was pertaining to the fact that when you create a migration with Laravel’s built-in command and put timestamps and soft deletes in the migration, the migration generator should detect this and add the appropriate Laravel specific traits, instead of creating columns. It might do this already, now, it’s been a year. Also for what it’s worth, I use this lib in conjunction with krlove:generate:model, to Laravelize older projects.