PHP code example of tonini46 / laravel-hooks-plus

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

    

tonini46 / laravel-hooks-plus example snippets


do_action(  string $tag,  mixed $arg )

add_action( string $tag, callable $callback, int $priority = 10, int $accepted_args = 1 )

apply_filters( string $tag, mixed $value )

add_filter( string $tag, callable $callback, int $priority = 10, int $accepted_args = 1 )

add_action('user_created', function($user) {
    $user->sendWelcomeMail();
}, 20, 1);

add_action('user_created', 'MyNamespace\Http\MyClass@myMethod', 20, 1);

add_action('user_created', [$object, 'myMethod'], 20, 1);

do_action('user_created', $user);

add_action('user_created', function($user) {
    $user->sendWelcomeMail();
}, 20, 1);

class Post extend Model
{
    public function getPublished()
    {
        return Post::where('published_at', '>', now());
    }
}

class Post extend Model
{
    public function getPublished()
    {
        return apply_filters('posts_published', Post::where('published_at', '>', now());
    }
}

class ModuleServiceProvider extends ServiceProvider
{
    public function boot()
    {
        add_filter('posts_published', function($query) {
            return $query->where('status', 'active');
        });
    }
}