Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Čamo's avatar
Level 3

What is boot in Model

I would like to know how boot method works in Model classes but I dont see it in documentation. Can somebody give me a link to doc?

class Product extends Model 
{
	protectd static function boot()
	{

	}
}
0 likes
5 replies
Snapey's avatar

how it works? It is called when the framework instantiates an eloquent model.

Čamo's avatar
Level 3

Ok I have more specific problem. This code uses something like (new SeoController())->updateModel($model)

    protected static function boot()
    {
        parent::boot();
        self::saved(function ($model) {
            (new SeoController())->updateModel($model);
        });
        self::created(function ($model) {
            (new SeoController())->updateModel($model);
        });
        self::retrieved(function ($model) {
            if (app()->getLocale() != config('app.fallback_locale')) {
                $model->localize();
            }
        });

What pattern is it? Why controller is called from model. It looks like anti-pattern.

Snapey's avatar
Snapey
Best Answer
Level 122

no,does not look correct but just because something has the name controller it does not mean it is one. Someone could have used this as somewhere to dump some code because they did not know any better

Čamo's avatar
Level 3

Ok thanks for help. It is little weird code...

Please or to participate in this conversation.