PHP code example of axn / laravel-notifier
1. Go to this page and download the library: Download axn/laravel-notifier 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/ */
axn / laravel-notifier example snippets
notify()->info('message');
notify()->success('message');
notify()->warning('message');
notify()->error('message');
class function PostController()
{
public function update(Post $post)
{
//...
$post->update([/*...*/]);
notify()->success('Post '.e($post->title).' successfully updated.');
return back();
}
}
notify()->nowInfo('message');
notify()->nowSuccess('message');
notify()->nowWarning('message');
notify()->nowError('message');
class function PostController()
{
public function edit(Post $post)
{
//...
notify()->nowInfo('Editing '.e($post->title).' post.');
return view('post.edit');
}
}
notify()->success('Post '.e($post->title).' successfully updated.', 'Success');
notify()->nowInfo('Editing '.e($post->title).' post.', 'Information');
notify()->success('Post '.e($post->title).' successfully updated.', 'Success', 5000);
notify()->nowInfo('Editing '.e($post->title).' post.', 'Information', 15000);
// messages flash
notify()
->info('message')
->success('message')
->when($condition, function($notify) {
$notify->warning('message');
})
->unless($otherCondition, function($notify) {
$notify->error('message');
});
// messages instantanés
notify()
->nowInfo('message')
->nowSuccess('message')
->when($condition, function($notify) {
$notify->nowWarning('message');
})
->unless($otherCondition, function($notify) {
$notify->nowError('message');
});
notify()->success('message'); // stack par defaut
notify('custom-stack')->success('message'); // stack personnalisée
notify()->nowInfo('message'); // stack par defaut
notify('custom-stack')->nowInfo('message'); // stack personnalisée
notify('custom-stack')
->nowInfo('message')
->nowSuccess('message')
->when($condition, function($notify) {
$notify->nowWarning('message');
});
class function PostController()
{
public function post(Request $request)
{
//...
return back()->withErrors([
'Une erreur',
'Une autres erreur',
])
}
}
notify()->flashMessages();
notify()->nowMessages();
notify('custom-stack')->flashMessages();
notify('custom-stack')->nowMessages();
notify()
->when($condition, function($notify) {
$notify->warning('message');
})
->unless($otherCondition, function($notify) {
$notify->error('message');
});
if (notify()->flashMessages()->isNotEmpty()) {
return back();
}
//...
'group_messages_format' => '<ul class="list-unstyled mb-0">%s</ul>',
'group_title_format' => '<strong>%s : </strong>',
'group_message_format' => '<li>%s%s</li>',
//...
[
'id', // l'identifiant unique du message
'type', // le type du message ('info', 'success', 'warning' ou 'error')
'message', // le contenu du message
'title', // l'éventuel titre du message
'delay', // la durée d'affichage du message
]
js
PNotify.defaultStack.close(true);
PNotify.defaultStack.maxOpen = Infinity;
PNotify.defaultStack.modal = false;
PNotify.defaults.animateSpeed = 'slow';
PNotify.defaults.delay = 5000;
PNotify.defaults.titleTrusted = true;
PNotify.defaults.textTrusted = true;
PNotify.defaults.styling = 'bootstrap4';
PNotify.defaults.icons = 'fontawesome5';
PNotify.defaultModules.set(PNotifyMobile, {});
PNotify.defaultModules.set(PNotifyAnimate, {
inClass: 'bounceInDown',
outClass: 'bounceOut'
});
PNotify.defaultModules.set(PNotifyBootstrap4, {});
PNotify.defaultModules.set(PNotifyFontAwesome5, {});
sh
php artisan vendor:publish --tag="notifier-views"
blade
<div>
@foreach ($flashMessages as $flashMessage)
{!! ici votre implémentation d'affichage d'un message !!}
@endforeach
@foreach ($nowMessages as $nowMessage)
{!! ici votre implémentation d'affichage d'un message !!}
@endforeach
</div>
blade
<div>
@foreach ($flashMessages as $flashMessage)
@ashMessage['type'],
'message' => $flashMessage['message'],
'title' => $flashMessage['title'],
'errorsCount' => $flashErrorsCount,
])
@endforeach
@foreach ($nowMessages as $nowMessage)
@
sh
php artisan vendor:publish --tag="notifier-config"