3 options i can think of (assuming i understand your question correctly, as it's a little broken english).
There already exists a "CREATED_AT" timestamp which you could use. You can change the name of column in your database if you like by editing your model like so:
class MyCustomModel extends Model {
const CREATED_AT = "date_started";
}
the created_at timestamp should only ever be set on new records, and there should be nothing stopping you manually changing that (such as in a form) afterwards.
Whenever you create a new record, manually set a date_started attribute to the current date in the list of attributes you want to save. You can either do this along with the other attributes you set on the model, or you can use model events as described here: http://laravel.com/docs/eloquent#model-events
You cannot use "default to current date" in MySQL for anything other than TIMESTAMP fields, if you want to stay with a human readable date or datetime field, then you cannot do this, otherwise change it to this:
$table->timestamp('date_started')->default(DB::raw('CURRENT_TIMESTAMP'));
I recommend the first option as the best option though
Thank you very much! This did the trick! I'm going to use the thirth option or make those field timestamps in the future
leesherwood said:
[ snip ]
- You cannot use "default to current date" in MySQL for anything other than TIMESTAMP fields, if you want to stay with a human readable date or datetime field, then you cannot do this, [ snip ]
I assume you're saying that TIMESTAMP fields are not human-readable in MySQL? If so then I believe that's true for older versions of MySQL but since version 5.6.5, I believe they're stored the same as a datetime (as per this MySQL page).
In Laravel 5.1 use
$table->timestamp('date_started')->useCurrent = true;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community