1. Go to this page and download the library: Download flavorly/inertia-flash 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 / inertia-flash example snippets
return [
/*
|--------------------------------------------------------------------------
| Driver Configuration
|--------------------------------------------------------------------------
|
| You can configure inertia flash to use session or cache as the driver.
| when using the cache driver inertia flash 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 : inertia_container_
| Cache TTL : Time in seconds to store the keys in cache.
*/
'prefix_key' => 'inertia_container_',
'driver' => 'session',
'session-driver' => \Flavorly\InertiaFlash\Drivers\SessionDriver::class,
'cache-driver' => \Flavorly\InertiaFlash\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.
|
*/
'persistent-keys' => [
// 'some-key' => 'some-value',
// 'messages => [],
],
/*
|--------------------------------------------------------------------------
| Ignore URLs & Params
|--------------------------------------------------------------------------
|
| The URls to ignore by default, because inertia runs on web middleware
| Default For URLS: ['broadcasting/auth']
|
*/
'ignore_urls' => [
'broadcasting/auth',
],
];
use Flavorly\InertiaFlash\InertiaFlash;
// Resolve from container
$flash = app(\Flavorly\InertiaFlash\InertiaFlash::class);
$flash->share('foo', 'bar');
// Or using the helper
inertia_flash()->share('foo', 'bar');
// With a closure that will be serialized
inertia_flash()->share('foo', fn() => 'bar');
// With a nested closure
inertia_flash()->share('foo', ['bar' => 'foo', 'baz' => fn() => 'bar']);
// On Controllers return back()
return back()->inertia('foo', 'bar');
// return back() + Closures
return back()->inertia('foo', function () {
return 'bar';
});
// Or the way cool way
inertia_flash()->share('foo', fn() => 'bar');
// Returning + the cool way
return back()->inertia('foo', fn() => 'bar');
// Appending Data
inertia_flash()->share('fruits', 'bananas',true);
inertia_flash()->share('fruits', 'oranges', true);
// Conditional Sharing
inertia_flash()->shareIf($foo === true, 'foo', 'bar');
inertia_flash()->shareUnless($foo === false, 'foo', 'bar');
// Appending
// You can also use append on regular share method as the third parameter
inertia_flash()->append('foo', 'bar');
// Sharing to a user
// Only available if driver is cache, otherwise session will always use the current logged user
inertia_flash()->forUser($user)->append('foo', 'bar');
notification()
->message('Thanks for your order! Your welcome on Site! ')
->viaInertia()
->dispatch();
notification()
->dialog()
->title('Thanks for your order!')
->message('Thanks for your order! Your welcome on Site! ')
->icon('🎉')
->block(fn (NotificationContentBlock $block) => $block->icon('🎉'))
->block(fn (NotificationContentBlock $block) => $block->title('Thanks for your order!'))
->block(fn (NotificationContentBlock $block) => $block->text('Your welcome on Site!'))
->block(fn (NotificationContentBlock $block) => $block->image('https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExeXRmMHp4N2o1bjQ2ajg0bXEyMmt5OXJrdW8zcmxqbHJ1MTNjZmdxbyZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/Cm9wKmKMUlRPvdoHgU/giphy-downsized-large.gif'))
->viaInertia()
->dispatch();
notification()
->message('Thanks for your order! Your welcome on Site! ')
->icon('🎉')
->dispatch();
notification()
->message('Thanks for your order! Your welcome on Site!')
->success()
->dialog()
->dispatch();
notification()
->message('Thanks for your order! Your welcome on Site!')
->error()
->toast()
->dispatch();
notification()
->message('Thanks for your order! Your welcome on Site!')
->warning()
->flash()
->dispatch();
notification()
->title('Thanks for your order!'.time())
->message('Thanks for your order! Your welcome on site! '.time())
->icon('majesticons:add-column')
->dispatch();