1. Go to this page and download the library: Download mbarlow/megaphone 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/ */
mbarlow / megaphone example snippets
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use MBarlow\Megaphone\HasMegaphone;
class User extends Authenticatable
{
use Notifiable;
use HasMegaphone;
}
$notification = new \MBarlow\Megaphone\Types\Important(
'Expected Downtime!', // Notification Title
'We are expecting some downtime today at around 15:00 UTC for some planned maintenance. Read more on a blog post!', // Notification Body
'https://example.com/link', // Optional: URL. Megaphone will add a link to this URL within the Notification display.
'Read More...' // Optional: Link Text. The text that will be shown on the link button.
);
namespace App\Megaphone;
use MBarlow\Megaphone\Types\BaseAnnouncement;
class MyCustomNotification extends BaseAnnouncement
{
}
/*
* Custom notification types specific to your App
*/
'customTypes' => [
/*
Associative array in the format of
\Namespace\To\Notification::class => 'path.to.view',
*/
\App\Megaphone\MyCustomNotification::class => 'megaphone.my-custom-notification',
],
$notification = new \App\Megaphone\MyCustomNotification(
'Hello World',
'This is a custom notification, hope you like our app!'
);
$user = \App\Models\User::find(1);
$user->notify($notification);
namespace App\Megaphone;
use MBarlow\Megaphone\Types\BaseAnnouncement;
class MyCustomNotification extends BaseAnnouncement
{
public static function name(): string
{
return 'Awesome Notification';
}
}