Written by
laravel-style
on
on
Laravel Model의 boot()
Laravel Model의 boot()
laravel-news.com/eloquent-tips-tricks
3. Momdel boot() method
Eloquent 모델을 기본행동을 재정의하는 곳을 'boot()'라 한다.
class User extends Model { public static function boot() { parent::boot(); static::updating(function($model) { // do some logging // override some property like $model->something = transform($something); }); } }
아마도 가장 인기있는 예는 모델객체가 만들어질 때, 필드를 세팅하는 것이다.
다음과 같이 UUID필드를 초기화 할 있다.
public static function boot() { parent::boot(); self::creating(function ($model) { $model->uuid = (string)Uuid::generate(); });
from http://starziki.tistory.com/73 by ccl(A) rewrite - 2021-02-28 09:00:48