PHP code example of salioudiabate / notify

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

    

salioudiabate / notify example snippets


Notify::success('Utilisateur créé avec succès.');

Notify::confirm('Supprimer ce client ?', 'Cette action est irréversible.')
    ->danger()
    ->onConfirm(fn () => $client->delete())
    ->show();

$import = Notify::loading('Import des données...');
// ... work happens ...
$import->success('Import terminé.');

class ClientController extends Controller
{
    public function destroy(Client $client)
    {
        $client->delete();

        return Notify::success('Client supprimé.')->redirectTo(route('clients.index'));
    }
}

use Livewire\Component;
use Salioudiabate\Notify\Concerns\InteractsWithNotifications;

class DeleteClientButton extends Component
{
    use InteractsWithNotifications;

    public function delete(Client $client)
    {
        $client->delete();

        $this->notify('Client supprimé.');
    }

    public function askToDelete(Client $client)
    {
        $this->confirm(
            title: 'Supprimer ce client ?',
            message: 'Cette action est irréversible.',
            action: 'delete',
            params: ['client' => $client->id],
        );
    }
}

$this->notifyBuilder()->asError()->title('Oups')->message('...')->group('errors')->send();

$this->confirmBuilder('Supprimer définitivement ?', 'Cette action est irréversible.')
    ->danger()
    ->confirmColor('#dc2626')
    ->onConfirm('delete', ['client' => $client->id])
    ->send();

Notify::success($message, $title = null);
Notify::error($message, $title = null);
Notify::warning($message, $title = null);
Notify::info($message, $title = null);

Notify::toast()->asSuccess()->title('Succès')->message('...')->duration(5000)->send();

// alert() covers both a one-off important notice (button() alone) and a
// persistent banner (add action() too) — same builder, more actions
Notify::alert()->asWarning()->title('Attention')->message('...')->button('Compris')->show();
Notify::alert()->asInfo()->title('Maintenance programmée')->message('...')
    ->action('En savoir plus', 'https://...', 'link')->button('Fermer')->show(); // persists until dismissed

// button()'s label is all it needs for a plain dismiss button (above) — pass
// a target too (any of action()'s: a route, a URL, a Livewire method, a
// Closure) and/or a color for a real call to action instead:
Notify::alert()->asInfo()->title('Nouveau message')->message('...')
    ->button('Voir', null, 'messages.index')->show();

// one-liners for the common "banner with this message" case, mirroring
// success()/error()/warning()/info() above for toast() — use alert() directly
// for anything more custom (a button() with its own target, group(), ...)
Notify::alertSuccess($message, $title = null);
Notify::alertError($message, $title = null);
Notify::alertWarning($message, $title = null);
Notify::alertInfo($message, $title = null);

Notify::confirm('Titre', 'Message')->danger()->confirmText('Supprimer')->onConfirm(...)->show();

// dialog() is free-form (any number of action() buttons) — centered() switches
// to the single-button, celebratory layout; without it you get a regular modal
Notify::dialog()->asSuccess()->centered()->title('Paiement réussi')->message('...')->action('Continuer')->show();

// called from inside a Livewire component method: 'signOut' resolves to
// $this->signOut() on that same component — the same target resolution
// onConfirm() uses (a route name or URL always wins first, see below)
Notify::dialog()->asInfo()->title('Session bientôt expirée')->message('...')
    ->action('Se déconnecter', 'signOut')->action('Rester connecté', null, 'primary')->show();

Notify::progress()->title('Importation')->progress(45)->status('Lot 4 sur 7')->send();

$pending = Notify::loading('Traitement...');
$pending->success('Terminé.');   // swaps the same card in place
$pending->progress(80);

Notify::update($id)->success('Terminé.')->send();
Notify::clearGroup('users');
Notify::dismiss($id);  // closes one already-rendered notification remotely
Notify::clearAll();    // closes every currently-rendered notification remotely
Notify::exception($e); // never leaks $e->getMessage() in production unless configured to

$pending->dismiss(); // same as Notify::dismiss($pending->id()), targeting the right component automatically

ToastBuilder::macro('forTenant', function (Tenant $tenant) {
    return $this->meta(['tenant' => $tenant->id]);
});

Notify::toast()->asSuccess()->message('...')->forTenant($tenant)->send();

Notify::toast()->asSuccess()->title('Fait')->message('...')->template('brand')->send();

'theme' => 'brand',

// config/notify.php — same effect, applied server-side, no inline <script> needed
'icons' => [
    'success' => '<svg>...</svg>',
],

Notify::success('Done.')->icon('<svg>...</svg>')->send();

// config/notify.php — same effect, applied globally without a <script> tag;
// leave any key out to keep its built-in French default. Keys are snake_case
// here, like every other key in this file — Notify.setStrings() above uses
// the camelCase spelling of the same keys since that one's a plain JS object;
// <x-notify::root /> translates between the two.
'strings' => [
    'close' => 'Close',
    'more_singular' => 'more notification',
    'more_plural' => 'more notifications',
    'esc_key' => 'Esc',
    'esc_hint' => 'to close',
    'confirm' => 'Confirm',
    'cancel' => 'Cancel',
    'url' => 'View',
    'action_success' => 'Done.',
    'action_error' => 'Something went wrong.',
],

// config/notify.php — same effect, applied server-side
'button_colors' => [
    'primary' => ['bg' => '#7c3aed', 'fg' => '#ffffff'],
],

Notify::toast()->asSuccess()->message('Done.')->action('Undo', fn () => $this->undo(), 'primary', '#7c3aed')->send();

Notify::confirm('Delete this?')
    ->confirmColor(['bg' => '#dc2626', 'fg' => '#fff'])
    ->cancelColor('#e5e7eb')
    ->onConfirm(fn () => $this->delete())
    ->send();

// config/notify.php — forces it site-wide regardless of the visitor's OS setting
'color_scheme' => 'dark', // null (default) | 'light' | 'dark'

// from a queued job, once the export is actually ready — the user could be
// anywhere else in the app, or not even online, by the time this runs
Notify::toast()->asSuccess()->message('Votre export est prêt.')->toUser($user)->send();

// or an arbitrary channel name instead of the notify.{id} convention toUser() uses
Notify::toast()->asInfo()->message('...')->toChannel('team.acme.alerts')->send();

// routes/channels.php
Broadcast::channel('notify.{id}', fn ($user, $id) => (int) $user->id === (int) $id);

// config/notify.php
'broadcast' => [
    'enabled' => true,
    'channel' => null, // null = notify.{auth()->id()} per visitor, skipped entirely as a guest
],

'channel' => fn ($request) => $request->user()?->currentTeam?->broadcastChannel(),

$pending = Notify::toast()->loading()->message('Export en cours…')->toUser($user)->send();
// ... later, from the same job ...
$pending->success('Export terminé.'); // reaches the same notify.{$user->id} channel

Notify::confirm('Supprimer ce fichier ?')
    ->danger()
    ->onConfirm(fn () => Storage::delete($file))
    ->show();

Notify::confirm('Supprimer ce client ?')->danger()->onConfirm(function () use ($clientId) {
    $client = Client::findOrFail($clientId);
    Gate::authorize('delete', $client); // re-checked now, not assumed from earlier
    $client->delete();
})->show();
bash
php artisan vendor:publish --tag=notify-assets
blade
{{-- notifyAction(): loading -> Livewire call -> success/error, wired as one Alpine expression --}}
<button @click="{{ $this->notifyAction('delete', ['client' => $client->id], loading: 'Suppression…', success: 'Client supprimé.', error: 'Échec de la suppression.') }}">
    Supprimer
</button>
bash
php artisan vendor:publish --tag=notify-config