Download the PHP package goomcoom/laravel-messages without Composer
On this page you can find all versions of the php package goomcoom/laravel-messages. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download goomcoom/laravel-messages
More information about goomcoom/laravel-messages
Files in goomcoom/laravel-messages
Package laravel-messages
Short Description Sometimes you may wish to return responses with some extra messages informing the user of what happened. This package provides a fluent interface to add messages from anywhere within in your code base and gracefully add them to your JSON responses.
License MIT
Informations about the package laravel-messages
Laravel Messages
Sometimes you may wish to return responses with some extra messages informing the user of what happened. This package provides a fluent interface to add messages from anywhere within in your code base and gracefully add them to your JSON responses.
Installation
Install the package using composer.
The service provider and facade are registered automatically, but you may do so manually by adding them to the app config.
Config
To publish the config file you may use the following command
The config file holds the bags that are available for accepting messages which are fully customizable.
Adding messages to responses
If you would like the messages to the added to the response automatically, you may use the AddMessagesToResponse
middleware. The middleware checks if there are any messages and adds them to the response's meta content.
For information on using middleware please refer to the official documentation.
The middleware also checks if the response has a message property and appends the message to the
meta.messages.error
array.
Adding messages
The first argument is the message bag that the messages are meant to be added to. We use the splat operator to gather messages, so you may add multiple comma-separated messages at once.
It's worth noting that messages are not duplicated within a category.
Getting a bag
The package uses laravel's MessageBag class
to categorise the messages. You may retrieve a specific bag using the getBag
method.
Getting all messages
You may also retrieve all the messages as an associative array with the messages grouped by their category by using the
getAll
method.
Checking if any messages have been added
You may check if any messages have been added by using the hasAny
method.
Removing messages
You may remove messages from a specific bag by using the remove
method.
Resetting all message bags
You may reset all message bags by calling the reset
method.