Package Data | |
---|---|
Maintainer Username: | davidkyalo |
Maintainer Contact: | davidmkyalo@gmail.com (David Kyalo) |
Package Create Date: | 2014-04-08 |
Package Last Update: | 2014-06-19 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:09:40 |
Package Statistics | |
---|---|
Total Downloads: | 25 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 3 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Ahem is a simplly enables you to :-
Add the following to your composer.json
"codenest/ahem": "dev-master"
Then run composer update
in your terminal.
In order to start using Ahem, you need to add it's service provider and facade in your application. To do this open app/config/app.php
.
In your providers
array add
'Codenest\Ahem\AhemServiceProvider',
And in your aliases
array add
'Ahem' => 'Codenest\Ahem\Facades\Ahem',
By default, Ahem has success
, error
, warning
and info
notification types defined in its configuration file and you may wish to add your own, edit or remove some of these notification types. To do this, you need to publish the config file to your app by running the command below.
php artisan config:publish codenest/ahem
========================
Before getting into details, lets have a look at how we can use Ahem's default notification types.
Ahem::success()->message('Login was successfully. Welcome.');
Ahem::error()->message('Wrong email or password.');
Ahem::info()->message('Somebody send you a message');
Ahem::warning()->message('Your account subscription will expire in 3 days. Please renew.');
id
Ahem::success('login_success')->message('Login was successfully. Welcome.');
Ahem::error('login_error')->message('Wrong email or password.');
In the above case, I have used login_success
and login_error
as the ids. This id uniquely identified the notification and I recommend it if you have multiple notifications on one request and you would like to reference some of them at a later stage. As you saw in our first example, the id
is not necessary. Your can leave it blank and the notification will be assigned a unique integer id
.
Adding an array of messages with an heading.
Ahem::error('login_error')
->messages(array('email' => 'Enter a valid email address', 'password' => 'The password field is required'))
->heading('Something went wrong');
Adding validation error messages.
public function postLogin()
{
$rules = array (
'email' => 'email|required',
'password' => 'required'
);
$validator = Validator::make( Input::all(), $rules);
if($validator->passes())
{
Ahem::success('login_success')->message('Login was successfully. Welcome!!');
return Redirect::to('/');
}
else
{
Ahem::error('login_error')->messages($validator->messages())->heading('Something went wrong.');
return Redirect::back()->withInput();
}
}
As we are going to see later, notifications are automatically flashed into the session on creation and cleared once they are rendered, you might want to add notifications for a single requests that don't need to be flashed. We do this by simply setting flashable
to false
Ahem::error('login_error')->message('Login error. Try again.')->flashable(false);
=======================
{{ Ahem::renderAll() }}
{{ Ahem::renderAll(array('error', 'warning')) }}
{{ Ahem::renderError() }}
{{ Ahem::renderSuccess() }}
{{ Ahem::renderError('login_error') }}
{{ Ahem::renderSuccess('login_success') }}
I had mentioned before that after you render a flashed notification, It automatically be cleared from the session. In some cases, we might need to keep some notifications in the session even after they are rendered.
{{ Ahem::renderAllButKeep() }}
{{ Ahem::renderAllButKeep(array('error', 'warning')) }}
{{ Ahem::renderButKeepError() }}
{{ Ahem::renderButKeepSuccess() }}
{{ Ahem::renderButKeepError('login_error') }}
{{ Ahem::renderButKeepError('login_success') }}