Install this package via Composer by added the package and the repository link:
"require": {
"truefrontier/toast-builder": "dev-main",
}
"repositories": [
{
"type":"vcs",
"url": "https://github.com/truefrontier/toast-builder"
}
]
Then run:
composer updateLastly, to use the Toast Builder class, you can call it like so:
use Truefrontier\ToastBuilder\Classes\ToastBuilder;
// Object
$toast_builder = new ToastBuilder();
$toast = $toast_builder->toast([
'type' => 'info',
'title' => 'My New Toast',
'body' => 'This is only a test!'
]);
// Inline
$toast = (new ToastBuilder())->toast([
'type' => 'info',
'title' => 'My New Toast',
'body' => 'This is only a test!'
]);
// Predefined
$toast = (new ToastBuilder(['type' => 'info']))->toast(['title' => 'Predefined Type']);To use Toasts with Inertia, you'll have to update the Inertia Middleware to include:
// app/Http/Middleware/HandleInertiaRequests.php
use Truefrontier\ToastBuilder\Classes\ToastBuilder;
public function share(Request $request)
{
return array_merge(parent::share($request), [
'toasts' => (new ToastBuilder())->shareInertia($request),
]);
}The MIT License (MIT). Please see License File for more information.