Date convention

Using the something_at convention instead of just a boolean in Laravel models gives you visibility into when a flag was changed – like when a product went live.

1// Migration
2Schema::table('products', function (Blueprint $table) {
3 $table->datetime('live_at')->nullable();
4});
5 
6// In your model
7public function live()
8{
9 return !is_null($this->live_at);
10}
11 
12// Also in your model
13protected $dates = [
14 'live_at'
15];

Tip given by @alexjgarrett

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord