Laravel Dispatchable Event Trait (Events/Dispatchable.php)

framework · src/Illuminate/Foundation/Events/Dispatchable.php · php · MIT
automation, infra, lang:php, fw:laravel, tag:events, tag:dispatch

PHP trait providing static methods to dispatch events with conditional logic. Use in Laravel applications to implement event-driven architecture patterns.

// Source: https://github.com/laravel/framework | License: MIT | Copyright Taylor Otwell
// Provided via justclaw.it.com; keep this notice with the code.
<?php

namespace Illuminate\Foundation\Events;

trait Dispatchable
{
    /**
     * Dispatch the event with the given arguments.
     *
     * @param  mixed  ...$arguments
     * @return mixed
     */
    public static function dispatch(...$arguments)
    {
        return event(new static(...$arguments));
    }

    /**
     * Dispatch the event with the given arguments if the given truth test passes.
     *
     * @param  bool  $boolean
     * @param  mixed  ...$arguments
     * @return mixed
     */
    public static function dispatchIf($boolean, ...$arguments)
    {
        if ($boolean) {
            return event(new static(...$argume

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key