PHP code example of razu / laravel-hooks

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

    

razu / laravel-hooks 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_registered', function($user) {
    $user->sendEmailVerificationCode();
}, 20, 1);

add_action('user_registered', 'OurNamespace\Http\Listener\ourClass@ourHookListenerMethod', 20, 1);
add_action('user_registered', 'OurNamespace\Http\Controllers\ourController@ourMethodName', 20, 1);

add_action('user_registered', [$object, 'ourMethod'], 20, 1);

do_action('user_registered', $user);

add_action('user_registered', function($user) {
    $user->sendEmailVerificationCode();
}, 10, 1);

class Product extends Model
{
    public function getAvailable()
    {
        return Product::where('available_at', '<=', now());
    }
}

class Product extends Model
{
    public function getAvailable()
    {
        return apply_filters('products_available', Product::where('available_at', '<=', now()));
    }
}

class ModuleServiceProvider extends ServiceProvider
{
    public function boot()
    {
        // Registering a filter to modify the query for available products
        add_filter('products_available', function($query) {
            return $query->where('status', 'active');
        });
    }
}