BREAD > Browse sorts by created_at by default. If this column was not created, an error occurs.
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'created_at' in 'order clause' (SQL: select * fromexampleorder bycreated_atdesc)
Steps to reproduce the behavior:
As timestamp is enabled default by laravel so you need to add public $timestamps = false; in your model if you don't want timestamp.
This is correct, but then this field must always be created when a model is created for the table. Or a warning should appear when creating the tables.
Totally agree with @BoFiaZ
Whenever a new table is created at least a warning should appear on screen: a better solution would be to create both 'created_at' and 'updated_at' fields when creating a new table, or when creating BREAD for the table
@giuliogatto I don't agree on this. Timestamps should be optional and that's what the voyager provides but yes, ordering by created_at should be managed by the voyager.
Well, the problem for me is that when you do the following:
1) create new table from Admin
2) add BREAD from Admin
3) navigate to the new table
You get the mentioned error which is quite nasty to see.
I can see that in the Create new table form there is an 'Add timestamp' button which is very handy, but it should be more clear that if you don't add timestamps manually or add some code to the model then the application is going to break.
What about automatically adding public $timestamps = false; in any model without timestamps? This would prevent the nasty error.
What about automatically adding public $timestamps = false; in any model without timestamps? This would prevent the nasty error.
IMO instead of adding automatically, it should check if timestamp is set to false on that model while fetching and ordering the data from model.
Yes, that's a solution, too (If the error only appears while fetching and ordering data from model)
btw: thank you for the prompt response
Its not Voyager that fails if you dont have timestamps, its Laravel.
So we "can't" check that.
@emptynick Voyager fetch data and tries to order the data by created_at column but Laravel will throw exception if there is no timestamps. IMHO Voyager can order the data by created_at column if present otherwise order by default primary key column ?
@emptynick , if Voyager can't check that, what about adding public $timestamps = false; to the new models generated without Timestamp then?
@DrudgeRajen Laravel will still fail when saving new entries.
All this are Laravel conventions
@emptynick yeah got that. The developer should use public $timestamps = false; if timestamps are not needed. Is it documented? If not, I think it should be mentioned somewhere because viewing from upper-level everyone will think that it is handled in voyager since voyager provides the feature to add timestamps while creating a database.
It is documented here.
Closing due to inactivity/not Voyager related.
This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.
Most helpful comment
This is correct, but then this field must always be created when a model is created for the table. Or a warning should appear when creating the tables.