LaravelPackages.net
Acme Inc.
Toggle sidebar
inani/laravel-same-request

The missing Laravel's request check on its unicity.

803
10
1.3.0
About inani/laravel-same-request

inani/laravel-same-request is a Laravel package for the missing laravel's request check on its unicity.. It currently has 10 GitHub stars and 803 downloads on Packagist (latest version 1.3.0). Install it with composer require inani/laravel-same-request. Discover more Laravel packages by inani or browse all Laravel packages to compare alternatives.

Last updated

Motivation

Total Downloads

This laravel package will allow you to execute a code once in the current request based on the key provided.

Installation

composer require inani/laravel-same-request

You will(for L5) need to register the service provider in the config/app.php .

return [
       /*
         * Package Service Providers...
         */

        /*
         * Application Service Providers...
         */
        App\Providers\AppServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        // App\Providers\BroadcastServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        App\Providers\RouteServiceProvider::class,
        Inani\UniqueRequest\UniqueRequestServiceProvider::class, // <=== HERE
];

You will need to use the middleware or binding it globally in your app/Http/Kernel.php

return [
        'api' => [
                'throttle:120,1',
                'bindings',
                PreventCache::class,
                GetJwtFromCookie::class,
                AddUniqueIdentifier::class
         ],
];

Usage

    for ($i= 0; $i < 2; $i++){
        $greeting = request()->once(function (){
            info('entred once');
            return 'hello';
        }, 'greeting');
    }

    $goodbye = request()->once(function (){
        return 'Saynoara';
    }, 'bye');

    $goodbye = request()->once(function (){
        return 'ByeBye';
    }, 'bye');

    return [$greeting, $goodbye];

Comments