migrations-generator icon indicating copy to clipboard operation
migrations-generator copied to clipboard

Detection of timestamps & softDeletes

Open phpguru opened this issue 7 years ago • 3 comments

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 avatar Sep 08 '17 21:09 phpguru

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.

phpguru avatar Sep 08 '17 21:09 phpguru

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

cacpmw avatar Dec 04 '18 18:12 cacpmw

@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.

phpguru avatar Dec 08 '18 05:12 phpguru