PHP code example of reedware / laravel-events

1. Go to this page and download the library: Download reedware/laravel-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/ */

    

reedware / laravel-events example snippets




namespace App\Providers;

use Reedware\LaravelEvents\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{

}



namespace App\Providers;

use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Reedware\LaravelEvents\ConfiguredEvents;

class EventServiceProvider extends ServiceProvider
{
    use ConfiguredEvents;
}

/**
 * Returns the events and handlers.
 *
 * @return array
 */
public function listens()
{
    $myEventOverrides = [/* ... */];

    return array_merge_recursive(
        $myEventOverrides,
        $this->configuredEvents()
    );
}

'listen' => [

    // When a user has registered...
    Illuminate\Auth\Events\Registered::class => [

        // Send an email verification notification
        Illuminate\Auth\Listeners\SendEmailVerificationNotification::class

    ],

],

'listen' => [

    // When a user has registered...
    Illuminate\Auth\Events\Registered::class => [

        [App\Listeners\MyCustomListener::class, 'handleRegistration'],

        // or

        'App\Listeners\MyCustomListener@handleRegistration'

    ],

],



namespace App\Listeners;

use Illuminate\Auth\Events\Registered;

class MyCustomListener
{
    /**
     * Handles the specified registration event.
     *
     * @param  \Illuminate\Auth\Events\Registered  $event
     *
     * @return void
     */
    public function handleRegistration(Registered $event)
    {
        //
    }
}

'listen' => [

    // When a user has registered...
    Illuminate\Auth\Events\Registered::class => [

        // Handle the event
        App\Listeners\MyCustomListener::class,

    ],

],

'listen' => [

    // When a user has registered...
    Illuminate\Auth\Events\Registered::class => [

        // Send a slack notification
        App\Listeners\SendSlackNotification::class,

    ],

    // When a user has logged out...
    Illuminate\Auth\Events\Logout::class => [

        // Send a slack notification
        App\Listeners\SendSlackNotification::class,

    ],

],

'subscribe' => [

    // Log a security event...
    App\Listeners\LogSecurityEvent::class => [

        // When a user provided incorrect credentials
        Illuminate\Auth\Events\Failed::class,

        // When a user has been locked out
        Illuminate\Auth\Events\Lockout::class,

        // When a user has reset their password
        Illuminate\Auth\Events\PasswordReset::class,

    ],

],



namespace App\Listeners;

use Illuminate\Auth\Events\Failed;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Auth\Events\PasswordReset;

class LogSecurityEvent
{
    /**
     * Handles failed login attempts.
     */
    public function handleFailed(Failed $event)
    {
        //
    }

    /**
     * Handles too many login attempts.
     */
    public function handleLockout(Lockout $event)
    {
        //
    }

    /**
     * Handles successful password resets.
     */
    public function handlePasswordReset(PasswordReset $event)
    {
        //
    }
}

'subscribe' => [

    // Log a security event...
    App\Listeners\LogSecurityEvent::class => [

        // When a user provided incorrect credentials
        [Illuminate\Auth\Events\Failed::class, 'failed'],

        // When a user has been locked out
        [Illuminate\Auth\Events\Lockout::class, 'lockout'],

        // When a user has reset their password
        'Illuminate\Auth\Events\PasswordReset@reset',

    ],

],

'observe' => [

    // Track the creator for each of the following models...
    App\Observers\UserObserver::class => [

        App\Models\Country::class,
        App\Models\Post::class,
        App\Models\State::class,
        App\Models\User::class,

    ]

],

'models' => [

    // Observe the user
    App\Models\User::class => [
        App\Observers\UserObserver::class,
    ]

],

php artisan vendor:publish