I'm trying to detect if certain things have been processed by checking them against timestamp fields, but the fields that have not been assigned a value (that should be null) are coming up as '-0001-11-30 00:00:00'.
I'm assuming that since I have my timezone set to America/Phoenix, that when I pull the value from the model, Carbon is converting it as if it were '0000-00-00 00:00:00' into my timezone.
Now, I could hard-code it in so that I can compare the string '-0001-11-30 00:00:00', but if the timezone ever changes (e.g. a client on the east coast, or another country wants dates to show up in their local time), then I'll have to go through many parts of my code and change this as well.
Alternatively, I could remove the date from my $dates array so that it doesn't go through Carbon, but this is also not ideal.
So, my question is this: Can I have my cake and eat it too? (Can I use Carbon AND check for null dates?)
In case you want a visual representation of what I'm talking about:
I have a table, we'll call it Example because I'm creative and it will be less confusing.
Example has a field, last_processed. It was created like so:
// Migration
Schema::table('examples', function(Blueprint $table) {
// ...
$table->timestamp('last_processed')->nullable();
});
// Class
class Example extends Model {
// ...
protected $dates = [ /*...*/, 'last_processed'];
// ...
}
// Config
'timezone' => 'America/Phoenix',
// View
@if ($example->last_processed)
{{ $example->last_processed }}
@else
Hasn't been processed!
@endif
// Outputs "-0001-11-30 00:00:00" when it should output "Hasn't been processed!"