PHP code example of flavorly / hybridly-share

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

    

flavorly / hybridly-share example snippets



return [
    /*
    |--------------------------------------------------------------------------
    | Driver Configuration
    |--------------------------------------------------------------------------
    |
    | You can configure hybridly share to use session or cache as the driver.
    | when using the cache driver hybridly share will leverage your current
    | cache driver and attempt to save the temporary shared keys there.
    | A unique key is used to generate the unique key for each user
    |
    | Drivers: 'cache' or 'session' are supported.
    | Prefix Key : hybridly_container_
    | Cache TTL : Time in seconds to store the keys in cache.
    */

    'prefix_key' => 'hybridly_container_',
    'driver' => 'session',

    'session-driver' => \Flavorly\HybridlyShare\Drivers\SessionDriver::class,
    'cache-driver' => \Flavorly\HybridlyShare\Drivers\CacheDriver::class,

    'cache-ttl' => 60,

    /*
    |--------------------------------------------------------------------------
    | Persistent Keys
    |--------------------------------------------------------------------------
    |
    | Here you may configure the keys that should be persisted on the session,
    | even if they are empty they will be mapped to their primitives configured here.
    | Might not be needed since hybridly provides a persist method.
    */
    'persistent-keys' => [
        // 'some-key' => 'some-value',
        // 'messages => [],
    ],


    /*
    |--------------------------------------------------------------------------
    | Ignore URLs & Params
    |--------------------------------------------------------------------------
    |
    | The URls to ignore by default, because hybridly runs on web middleware
    | Default For URLS: ['broadcasting/auth',...]
    |
    */
    'ignore_urls' => [
         'nova-api*',
        'filament-api*',
        'broadcasting/auth',
        'telescope*',
        'horizon*',
        '_debugbar*',
        '_ignition*',
    ],
];

// Or using the helper
hybridly()->container()->share('foo', 'bar');
hybridly()->container()->share('foo', fn() => 'bar');
hybridly()->container()->append('fruits','bananas');
hybridly()->container()->append('fruits','potatoes');
hybridly()->container()->share('foo', ['bar' => 'foo', 'baz' => fn() => 'bar']);

// On Controllers return back()
return back()->hybridly('foo', 'bar');
return back()->hybridly('foo', fn() => 'bar');

// Conditional Sharing
hybridly()->container()->shareIf($foo === true, 'foo', 'bar');
hybridly()->container()->shareUnless($foo === false, 'foo', 'bar');
// Sharing to a user
// Only available if driver is cache, otherwise session will always use the current logged user
hybridly()->container()->forUser($user)->append('foo', 'bar');
bash
php artisan vendor:publish --tag="hybridly-share-config"