PHP code example of mckenziearts / laravel-notify

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

    

mckenziearts / laravel-notify example snippets


public function store()
{
    notify()
        ->success()
        ->title('⚡️ Laravel Notify is awesome!')
        ->send();

    return back();
}

notify()
    ->success()
    ->title('Welcome to Laravel Notify ⚡️')
    ->send();

notify()
    ->model(NotificationModel::Connect)
    ->success()
    ->title('Connection Found')
    ->message('Success Message Here')
    ->send();

// For success alert
notify()
    ->model(NotificationModel::Drake)
    ->success()
    ->send();
// or
notify()
    ->model(NotificationModel::Drake)
    ->error()
    ->send(); // for error alert

notify()
    ->model(NotificationModel::Smiley)
    ->success()
    ->title('You are successfully reconnected')
    ->send();

notify()
    ->model(NotificationModel::Emotify)
    ->success()
    ->title('You are awesome, your data was successfully created')
    ->send();

notify()
    ->success()
    ->title('Saved successfully')
    ->duration(3000) // 3 seconds
    ->send();

notify()
    ->warning()
    ->title('Important notice')
    ->duration(999999) // ~16 minutes
    ->send();

'timeout' => env('NOTIFY_TIMEOUT', 5000),

use Mckenziearts\Notify\Action\NotifyAction;

notify()
    ->success()
    ->title('User deleted successfully')
    ->actions([
        NotifyAction::make()
            ->label('Undo')
            ->action(route('users.restore', $user->id)),
        NotifyAction::make()
            ->label('View All')
            ->url(route('users.index')),
    ])
    ->send();

NotifyAction::make()
    ->label('View details')
    ->url(route('users.show', $user->id));

NotifyAction::make()
    ->label('Read documentation')
    ->url('https://laravel.com/docs')
    ->openUrlInNewTab();

NotifyAction::make()
    ->label('Restore')
    ->action(route('users.restore', $user->id));

// DELETE request
NotifyAction::make()
    ->label('Delete permanently')
    ->action(route('users.force-delete', $user->id))
    ->method('DELETE');

// PUT request
NotifyAction::make()
    ->label('Update status')
    ->action(route('users.activate', $user->id))
    ->method('PUT');

public function destroy(User $user)
{
    $user->delete();

    notify()
        ->success()
        ->title('User deleted')
        ->message('The user has been moved to trash')
        ->actions([
            NotifyAction::make()
                ->label('Undo')
                ->action(route('users.restore', $user->id))
                ->method('POST'),
            NotifyAction::make()
                ->label('View Trash')
                ->url(route('users.trash'))
                ->openUrlInNewTab(),
        ])
        ->send();

    return redirect()->route('users.index');
}

NotifyAction::make()
    ->label('Delete')
    ->action(route('users.delete', $user->id))
    ->method('DELETE')
    ->classes('text-red-600 hover:text-red-500 font-bold');

notify()->preset('common-notification')->send();

notify()->preset('common-notification', ['title' => 'This is the overridden title'])->send();

use Mckenziearts\Notify\Enums\NotificationType;
use Mckenziearts\Notify\Enums\NotificationModel;

'preset-messages' => [
    'user-updated' => [
        'type'    => NotificationType::Success,
        'model'   => NotificationModel::Toast,
        'title'   => 'User Updated',
        'message' => 'The user has been updated successfully.',
    ],
    'user-deleted' => [
        'type'    => NotificationType::Success,
        'model'   => NotificationModel::Toast,
        'title'   => 'User Deleted',
        'message' => 'The user has been deleted successfully.',
    ],
],
bash
php artisan vendor:publish --tag=notify-assets
php artisan vendor:publish --tag=notify-config