1 year ago by Master Jupiter

Relates to the lesson Build a classified ads site

Hi I am doing classified ad series. While creating database seeder for Area ->slug, Alex uses php creating method. Is that a function? I know only about create method.

In AppServiceProvider.php

public function boot()
    {
        Area::creating(function($area){
            $prefix = $area->parent ? $area->parent->name . ' ' : '';
            $area->slug = str_slug($prefix . $area->name);
        });
    }

1 year ago by Master Jupiter

I got my answers, It was covered in the following lesson:

https://www.codecourse.com/lessons/drying-up-with-eloquent-model-observers

1 year ago by Dmitriy Belyakov

Best answer

Alex registers event handler using "creating" method on Area model class. It is inherited from Illuminate\Database\Eloquent\Model which uses it through Illuminate\Database\Eloquent\Concerns\HasEvents trait. You can read more about events here and here Though I haven't found the way Alex registered an event handler in Laravel documentation. I think it is much simpler and faster to implement.

Sign in or create an account to reply to this topic.