PHP code example of jdw5 / surge-toast

1. Go to this page and download the library: Download jdw5/surge-toast 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/ */

    

jdw5 / surge-toast example snippets


public function share (Requesr $request): array
{
    return [
        ...parent::share($request),
        'toast' => $request->session()->get('toast')
    ]
}

public function __construct(
    public string $message,
    public ?string $type = ToastType::DEFAULT->value,
    public ?int $duration = self::DEFAULT_DURATION,
    public ?string $title,
    public ?mixed $custom,
) {}

toast(new ToastData('A message', 'info'));

toast(ToastData::from([
    'message' => 'A message',
    'duration' => 5000,
    'title' => 'A title',
    'custom' => ['key' => 'value']
    'type' => 'info',
]));

toast([
    'message' => 'Error message',
    'type' => 'error',
    'duration' => 5000,
]);

toast()->info('A message');
toast()->success('A message');
toast()->error('A message');
toast()->warning('A message');

toast()->info('A message')->duration(5000)->title('A title');