how to set the default value of an attribute on a laravel model

Solutions on MaxInterview for how to set the default value of an attribute on a laravel model by the best coders in the world

showing results for - "how to set the default value of an attribute on a laravel model"
Louka
20 Jul 2020
1/**
2 * The "booting" method of the model.
3 *
4 * @return void
5 */
6protected static function boot()
7{
8    parent::boot();
9
10    // auto-sets values on creation
11    static::creating(function ($query) {
12        $query->is_voicemail = $query->is_voicemail ?? true;
13    });
14}