1. Go to this page and download the library: Download victorycodedev/toastkit 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/ */
victorycodedev / toastkit example snippets
use Victorycodedev\ToastKit\Facades\Toast;
Toast::success('Changes saved')->show();
Toast::success('Saved')->show();
Toast::error('Something went wrong')->show();
Toast::warning('Storage almost full')->show();
Toast::info('Downloading...')->show();
Toast::neutral('Copied')->show();
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Victorycodedev\ToastKit\PendingToast;
use Victorycodedev\ToastKit\Facades\Toast;
final class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Toast::definePreset('contacts-sync', fn (PendingToast $toast) => $toast
->info()
->unique('contacts-sync')
->persistent()
->loading());
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Victorycodedev\ToastKit\PendingToast;
use Victorycodedev\ToastKit\Facades\Toast;
final class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Toast::definePreset('syncing', fn (PendingToast $toast) => $toast
->message('Syncing...')
->info()
->persistent()
->loading());
}
}
namespace App\Toasts;
use Victorycodedev\ToastKit\Facades\Toast;
final class ToastPresets
{
public static function register(): void
{
Toast::definePreset('payment-success', fn ($toast) => $toast
->success()->icon('check_circle')->animation('reveal')
->position('top')->duration(3000));
Toast::definePreset('payment-failed', fn ($toast) => $toast
->error()->icon('error')->animation('snap')->direction('left')
->position('top')->duration(5000));
Toast::definePreset('uploading', fn ($toast) => $toast
->info()->loading()->persistent());
}
}
namespace App\Providers;
use App\Toasts\ToastPresets;
use Illuminate\Support\ServiceProvider;
final class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
ToastPresets::register();
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Victorycodedev\ToastKit\PendingToast;
use Victorycodedev\ToastKit\Facades\Toast;
final class ToastServiceProvider extends ServiceProvider
{
public function boot(): void
{
Toast::definePreset('payment-success', fn (PendingToast $toast) => $toast
->success()
->icon('check_circle')
->animation('reveal')
->position('top')
->duration(3000));
Toast::definePreset('payment-failed', fn (PendingToast $toast) => $toast
->error()
->icon('error')
->animation('snap')
->direction('left')
->position('top')
->duration(5000));
Toast::definePreset('uploading', fn (PendingToast $toast) => $toast
->info()
->loading()
->persistent());
}
}
use Victorycodedev\ToastKit\Exceptions\PresetNotFoundException;
try {
Toast::preset('payment-success');
} catch (PresetNotFoundException $exception) {
// The requested preset was not registered.
}
// Before
catch (\InvalidArgumentException $exception) {
// ...
}
// Now
catch (\Victorycodedev\ToastKit\Exceptions\ToastKitException $exception) {
// ...
}
use Native\Mobile\Attributes\On;
use Victorycodedev\ToastKit\Events\ToastActionPressed;
Toast::error('Connection lost')
->action(
label: 'Retry',
id: 'retry',
)
->show();
#[On(ToastActionPressed::class)]
public function handleToastAction(
string $toastId,
string $actionId,
): void {
if ($actionId === 'retry') {
$this->retry();
}
}
use Native\Mobile\Attributes\On;
use Victorycodedev\ToastKit\Events\ToastShown;
use Victorycodedev\ToastKit\Events\ToastDismissed;
#[On(ToastShown::class)]
public function handleToastShown(string $toastId): void
{
// The toast is now visible.
}
#[On(ToastDismissed::class)]
public function handleToastDismissed(string $toastId, string $reason): void
{
// $reason is one of: timeout, swipe, programmatic, action.
}
namespace App\Screens;
use Native\Mobile\Attributes\On;
use Native\Mobile\Edge\NativeComponent;
use Victorycodedev\ToastKit\Events\ToastActionPressed;
use Victorycodedev\ToastKit\Facades\Toast;
class ToastDemoScreen extends NativeComponent
{
public ?string $toastId = null;
public function startUpload(): void
{
$this->toastId = Toast::info('Uploading...')
->persistent()
->show();
}
public function updateUpload(): void
{
if (! $this->toastId) {
return;
}
Toast::update($this->toastId)
->message('Uploading 50%...')
->show();
}
public function completeUpload(): void
{
if (! $this->toastId) {
return;
}
Toast::update($this->toastId)
->message('Upload complete')
->success()
->icon('check')
->duration(2000)
->show();
}
public function dismissToast(): void
{
if ($this->toastId) {
Toast::dismiss($this->toastId);
}
}
}
use Native\Mobile\Attributes\On;
use Victorycodedev\ToastKit\Facades\Toast;
#[On(FetchDownloadProgress::class)]
public function onDownloadProgress(
string $requestId,
int $bytesReceived,
?int $bytesTotal,
?float $progress,
): void {
if ($progress === null || ! $this->toastId) {
return;
}
Toast::update($this->toastId)
->message(
'Downloading '.(int) round($progress * 100).'%...'
)
->show();
}
#[On(FetchDownloadCompleted::class)]
public function onDownloadCompleted(): void
{
Toast::update($this->toastId)
->message('Download complete')
->success()
->icon('check')
->duration(2000)
->show();
}
#[On(FetchRequestFailed::class)]
public function onDownloadFailed(): void
{
Toast::update($this->toastId)
->message('Download failed')
->error()
->duration(3000)
->show();
}
use Native\Mobile\Attributes\On;
use Victorycodedev\ToastKit\Events\ToastDismissed;
#[On(ToastDismissed::class)]
public function handleToastDismissed(string $toastId, string $reason): void
{
// $reason is one of: timeout, swipe, programmatic, action.
}
use Native\Mobile\Testing\Native;
Native::test(ProfileScreen::class)
->call('save')
->assertToastShownWithMessage('Profile updated');
use Native\Mobile\Testing\Native;
use Victorycodedev\ToastKit\Events\ToastActionPressed;
Native::test(ProfileScreen::class)
->emitNative(ToastActionPressed::class, [
'toastId' => 'one',
'actionId' => 'retry',
])
->assertSet('retried', true);