PHP code example of rdcstarr / superpower-events

1. Go to this page and download the library: Download rdcstarr/superpower-events library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rdcstarr / superpower-events example snippets


use Rdcstarr\SuperpowerEvents\Concerns\DispatchesModelEvents;

class User extends Model
{
    use DispatchesModelEvents;
}

use Rdcstarr\SuperpowerEvents\Concerns\ModelCreated;

class AssignUserUuid
{
    use ModelCreated;

    protected function handleModel(User $user): void
    {
        // Called only for User models — other model types are filtered
        // automatically by reflecting on the parameter type of handleModel().
        $user->uuid = Str::uuid();
        $user->saveQuietly();
    }
}

use Rdcstarr\SuperpowerEvents\Concerns\ModelCreating;

class SlugifyPost
{
    use ModelCreating;

    protected function handleModel(Post $post): void
    {
        $post->slug = Str::slug($post->title);
    }
}