PHP code example of luizfabianonogueira / sse-notify
1. Go to this page and download the library: Download luizfabianonogueira/sse-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/ */
luizfabianonogueira / sse-notify example snippets
return [
// other providers...
LuizFabianoNogueira\SseNotify\SseServiceProvider::class,
];
$data = [
'title' => 'Notify title Sweet!', //string
'message' => 'Notify message Sweet!', //string
'type' => SseEnumStyle::STYLE_SUCCESS, //Enum types: STYLE_SUCCESS, STYLE_ERROR, STYLE_WARNING, STYLE_INFO
'id' => time(),// int id unique
'confirm' => false, // if true show confirm button
'userId' => $this->userId //uuid - user to be notified
];
(new SseEventMessageSweet($data))->save();
$data = [
'title' => 'Notify title notify!', //string
'message' => 'Notify message notify!', //string
'type' => SseEnumStyle::STYLE_SUCCESS, //Enum types: STYLE_SUCCESS, STYLE_ERROR, STYLE_WARNING, STYLE_INFO
'id' => time(), // int id unique
'autoClose' => true, // if true auto close
'userId' => $this->userId //uuid - user to be notified
];
(new SseEventMessageNotify($data))->save();
$data = [
'title' => 'Notify title toast!', //string
'message' => 'Notify message toast!', //string
'type' => SseEnumStyle::STYLE_SUCCESS, //Enum types: STYLE_SUCCESS, STYLE_ERROR, STYLE_WARNING, STYLE_INFO
'id' => time(), // int id unique
'autoClose' => true, // if true auto close
'userId' => $this->userId, //uuid - user to be notified
'imgURL' => '/android-chrome-192x192.png', //string - image url [optional]
'linkURL' => 'https://www.google.com', //string - link url [optional]
'linkText' => 'Google' //string - link text [optional]
];
(new SseEventMessageToast($data))->save();
(new SseEventInjectHtml([
'html' => '<div class="alert alert-success">Notify message!</div>', //string - html to be injected
'target' => 'boxTestes', //string - target id to inject
'userId' => $this->userId //uuid - user to be notified
]))->save();
(new SseEventInjectScript([
'script' => 'console.log("Notify message! - ' . $i . '")', //string - script to be injected
'userId' => $this->userId //uuid - user to be notified
]))->save();
html
@if(Auth::check())
<!-- Include the sse.js file -->
<script src="{{ asset('assets/js/sse.js') }}"></script>
<script>
<!-- Call the SseConnect function passing the route to the connection -->
SseConnect('{{ route('sse.connect', ['userId' => Auth::user()->id]) }}');
</script>
@endif
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.