Download the PHP package mbarlow/megaphone without Composer

On this page you can find all versions of the php package mbarlow/megaphone. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package megaphone

Author Latest Version Software License Build Status

Megaphone is a Laravel Livewire based component that uses the power of Laravels built in Notifications system to allow you to add "Bell Icon Notification System" to your app.

Megaphone also ships with an Admin form component that allows you to send out a notification to all your users at once. Perfect for announcing new features or planned maintenance!

Server Management by ServerAuth.com

Demo

Before using Megaphone, a demo is available for you to view and try the Bell Icon component and Admin component. Aside from some minor styling changes to the Admin component so it fits the layout better, everything is "out the box" and will be exactly as is when you install Megaphone yourself.

View the Megaphone Demo

Upgrade from 1.x

Megaphone has been updated to support Livewire 3. This also means PHP requirements have been updated to match the requirements of Livewire 3 which means you need to be running PHP 8.1 or above (PHP 7.4 and 8.0 are no longer supported). Then make sure you follow the Livewire upgrade guide.

Update your Megaphone requirement to 2.* by running the following command in your terminal.

AlpineJS

If you previously included AlpineJS specifically for Megaphone then you can now remove that from your JS include because it is now bundled with Livewire.

Template Changes

If you are using the Admin component and are running with the Megaphone views published to your resources folder, you may wish to make these manual changes.

Changes are all to create-announcement.blade.php which, if published, should be found at resources/views/vendor/megaphone/admin/create-announcement.blade.php.

Find wire:model="type" and replace it with wire:model.live="type".

Find all instances of wire:model.lazy and replace it with wire:model.blur.

Installation

For the Livewire 2 version of Megaphone, see the 1.x versions of Megaphone and the 1.x branch.

Simply require the package via composer into your Laravel app.

composer require mbarlow/megaphone

If you aren't already using Laravel Livewire in your app, Megaphone should include the package via its dependency. Once composer has finished installing, make sure you run the Livewire installation steps.

Once Livewire has been installed, if you haven't already, ensure the Laravel Database Notifications have been installed into your app.

This should create database table used to house your notifications. Next, make sure your User model (or relevant alternative model) has the notifiable trait added as mentioned in the Laravel Documentation and also add the HasMegaphone trait provided by Megaphone.

Lastly, publish the Megaphone assets. This should publish the Config file as well as the templates and stylesheets. You can find the published templates within resources/views/vendor/megaphone.

If you are not using the default user model found at App\Models\User, you will need to amend the value of the model attribute, defined in the megaphone.php config file. Simply change the value to the path of your User model.

Using Megaphone

To get started using megaphone, drop in the Megaphone Livewire component into your template.

This will render a Bell Icon where the component has been placed. When clicked a static sidebar will appear on the right of the screen which will show all the existing and any new notifications to the user.

Styling

As default, Megaphone uses TailwindCSS to style the Bell Icon and the notification sidebar. If you are not using Tailwind you may want to include the Megaphone CSS into your template.

Sending Notifications

As default, Megaphone will only load notifications that have been registered within the Megaphone config file. Notifications shipped with Megaphone will be within config('megaphone.types'). This will be merged with the key values of config('megaphone.customTypes') to create the list of supported notifications.

This means, you can see use the Laravel Notification system for other parts of your system without them appearing in the Megaphone notifications list.

To send a Megaphone notification instantiate a new notification that extends MBarlow\Megaphone\Types\BaseAnnouncement. Megaphone ships with 3 as default, MBarlow\Megaphone\Types\General, MBarlow\Megaphone\Types\Important and MBarlow\Megaphone\Types\NewFeature.

Now, simply notify the required user of the notification as per the Laravel Documentation.

Next time User ID 1 visits your app, their Bell Icon will have a red indicator with "1" inside to denote 1 new, unread notification.

Custom Notifications

As mentioned, you can add your own notification types to Megaphone. In order to do this, first create a new class within your application and make sure it extends MBarlow\Megaphone\Types\BaseAnnouncement, for example:

Next you will need to create the view file for how Megaphone should render that notification. To get you started you can use the base template the General, Important and New Feature notifications uses. So for example, create a new view within resources/views/megaphone/my-custom-notification.blade.php.

Simply, add a relevant SVG Icon for your notification within the blade include parameters array, and you're good to go.

Lastly, you need to tell Megaphone about this notification. Open up the Megaphone config file config/megaphone.php and find the customTypes attribute. This should be an associative array with the FQDN of the notification class as the key and the path to the view as the value. For example,

Now you can trigger the notification and a user will receive it via their Bell Icon.

Admin Panel

The usage shown so far is great for automatic flows, for example, letting a user know an action has completed in the background, "Your file is ready for download", "Your server has finished setting up", etc... but sometimes you may want to send notifications en masse.

You may want to let users know that some downtime is expected for maintenance or that a cool new feature has launched. To cover these bases, Megaphone ships with an Admin component providing a form to send a notification to all users.

To use the component simply create a new page within your admin area, or create a password-protected page within your application that only you as the application owners can access and drop in this Livewire component.

Visit your page and you will be presented with a form, to first select the notification type and then fill out the title, body, link and link text. Once you have filled everything out, hit send to push the notification out to all users.

The form has been styled with TailwindCSS so if it doesn't look styled correctly make sure to include TailwindCSS on the page that is showing the Admin component. Alternatively, the view file will have been published along with the other Megaphone assets so you can customise the form styling within resources/views/vendor/megaphone/admin/create-announcement.blade.php.

Notification Type List

As default, the notification type list is created by merging the array of default notifications within config('megaphone.types'), with the key values of the custom types array found within config('megaphone.customTypes').

If you have added a lot of custom types or if you have some system notifications that should not be selectable from this type list, you can build your own type list within the adminTypeList attribute of the megaphone config.

Simply create an array of all the notification classes you wish to have available in the drop down list.

This example would mean only the default New Feature notification and your Custom Notification would be available from the drop down menu.

Type List - Notification Name

The name shown for each notification in the drop down menu is calculated from the class name within the BaseAnnouncement class that all Megaphone notifications extend. If Megaphone is unable to calculate the name of a custom notification correctly, or you wish to label it differently within the Admin Component type list, you can define a name() method within your notification. Megaphone will use this to display the label.

Clearing Old Notifications

To help keep your database and your users notifications tidy, Megaphone also ships with a console command that can be added to your apps schedule to clear old notifications.

Simply add the following to your Console/Kernal.php file within the schedule() method.

This will clear any "read" Megaphone notifications older than 2 weeks old. This allows any user that may not have logged in for a number of weeks to still view the notification before it would be cleared.

The 2-week time limit for old notifications is controlled via the Megaphone config file, config('megaphone.clearAfter'). So should you wish to alter this cut off point, simply change this value to either extend or shorten the cut off.

Changing Notifiable Model

Because notifications can be attached to any model via the Notifiable trait, Megaphone too can be attached to any model providing the model also has the Notifiable trait attached.

As default, Megaphone assumes you will be attaching it to the standard Laravel User model and when loading notifications, it will attempt to retrieve the ID of the logged in user from the Request object.

If you are wanting to attach Megaphone to a Team model for example, change the model attribute of the published megaphone config file, megaphone.php.

When rendering the Megaphone component, you will then need to pass in the ID of the notifiable model into the component so Megaphone can load the correct notifications

Testing

If you wish to run the tests, clone out the repository

Change to the root of the repository and run composer install with the dev dependencies

A script is defined in the composer.json to run both the code sniffer and the unit tests

Or run them individually as required

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.


All versions of megaphone with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
livewire/livewire Version ^3.0.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mbarlow/megaphone contains the following files

Loading the files please wait ....