This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Timur Shakirov
Timur Shakirov

I want to listen this event in my plugin and do certain actions. Help to collect a function of the wire.

\Event::listen('rainlab.post', function($post) {...}

Do I need to change the Rainlab code and write a Fire there? And how to do it?

Event::fire($this->asExtension('FormController')->create());
mjauvin
mjauvin
\RainLab\Blog\Models\Post::extend(function ($model) {
    $model->bindEvent('model.beforeCreate', function () use ($model) {
    // your code here 
    });
}) ;

or any of the other model events that better suit your needs

Timur Shakirov
Timur Shakirov

mjauvin said:

\RainLab\Blog\Models\Post::extend(function ($model) {
   $model->bindEvent('model.beforeCreate', function () use ($model) {
   // your code here 
   });
}) ;

or any of the other model events that better suit your needs

beforeCreate is real event? where can I see all the events? Can I use model.afterPublish?

Timur Shakirov
Timur Shakirov

mjauvin said:

\RainLab\Blog\Models\Post::extend(function ($model) {
   $model->bindEvent('model.beforeCreate', function () use ($model) {
   // your code here 
   });
}) ;

or any of the other model events that better suit your needs

if I understand correctly, the Rainlab Blog should have a fireEvent. for example, fireEvent('user.before Register', [$user]). That is, I need to change the code on my Rainlab Blog?

mjauvin
mjauvin

These are standard Laravel Events, you can find the list here: https://octobercms.com/docs/database/model#events

I don't recommand modifying any plugin's code directly, as your changes will be lost when the plugin gets updated.

If you want to know when the post is actually PUBLISHED, listen to the model.afterSave event for the RainLab\Blog\Models\Post model and check if the published field has been set like this:

public function boot()
{ 
     \RainLab\Blog\Models\Post::extend(function ($model) {
        $model->bindEvent('model.beforeSave', function () use ($model) {
            if ($model->published === true and $model->published != $model->getOriginal('published')) {
                // your code here
            }
        });
     });
}

1-5 of 5

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.