PHP code example of thbappy7706 / laravel-toastify

1. Go to this page and download the library: Download thbappy7706/laravel-toastify 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/ */

    

thbappy7706 / laravel-toastify example snippets


use Toastify\Laravel\Facades\Toastify;

public function store(Request $request)
{
    // Your logic here
    
    Toastify::success('User created successfully!');
    
    return redirect()->route('users.index');
}

// Other types
Toastify::error('Something went wrong!');
Toastify::warning('Please check your input!');
Toastify::info('New update available!');
Toastify::default('This is a toast message');

use Toastify\Laravel\Facades\Toastify;

class UserForm extends Component
{
    public function save()
    {
        // Your logic here
        
        $this->dispatch('toast:add', toast: [
            'type' => 'success',
            'message' => 'Data saved successfully!'
        ]);
    }
}

Toastify::success('Custom toast!', [
    'autoClose' => 3000,           // Auto close after 3 seconds
    'position' => 'bottom-right',   // Position
    'transition' => 'slide',        // Animation type
    'hideProgressBar' => false,     // Show progress bar
    'pauseOnHover' => true,         // Pause on hover
    'draggable' => true,            // Enable drag to dismiss
    'closeButton' => true,          // Show close button
    'rtl' => false,                 // Right-to-left
]);

// From PHP
Toastify::clear();

return [
    'position' => env('TOASTIFY_POSITION', 'top-right'),
    'transition' => env('TOASTIFY_TRANSITION', 'bounce'),
    'autoClose' => env('TOASTIFY_AUTO_CLOSE', 5000),
    'hideProgressBar' => env('TOASTIFY_HIDE_PROGRESS_BAR', false),
    'closeButton' => env('TOASTIFY_CLOSE_BUTTON', true),
    'pauseOnHover' => env('TOASTIFY_PAUSE_ON_HOVER', true),
    'pauseOnFocusLoss' => env('TOASTIFY_PAUSE_ON_FOCUS_LOSS', true),
    'draggable' => env('TOASTIFY_DRAGGABLE', true),
    'draggablePercent' => env('TOASTIFY_DRAGGABLE_PERCENT', 80),
    'rtl' => env('TOASTIFY_RTL', false),
    'newestOnTop' => env('TOASTIFY_NEWEST_ON_TOP', true),
    'theme' => env('TOASTIFY_THEME', 'light'),
];

'theme' => 'dark',

Toastify::success('Profile updated successfully!');

Toastify::error('Failed to save data!', [
    'autoClose' => 8000, // 8 seconds
]);

Toastify::warning('Your session will expire soon!', [
    'position' => 'bottom-center',
    'autoClose' => false, // Don't auto close
]);

Toastify::info('Check out our new features!', [
    'transition' => 'slide',
    'position' => 'top-left',
]);

Toastify::success('Item 1 added!');
Toastify::success('Item 2 added!');
Toastify::info('Cart updated!');

Toastify::success('تم الحفظ بنجاح!', [
    'rtl' => true,
]);
bash
php artisan vendor:publish --tag=toastify-config
php artisan vendor:publish --tag=toastify-views
php artisan vendor:publish --tag=toastify-assets