-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Completed Initial version of Flash Notifications
- Loading branch information
Showing
10 changed files
with
349 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/vendor | ||
.idea | ||
/bootstrap/compiled.php | ||
.env.*.php | ||
.env.php | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,75 @@ | ||
# flash-notifications | ||
Elegant Flash Notifications For Laravel | ||
Flash Notifications | ||
=================== | ||
|
||
**This is an experimental release.!** | ||
|
||
Laravel 5 flash notifications, originally developed after the Laracasts video tutorial : [Elegant Flash Messaging](https://laracasts.com/series/build-project-flyer-with-me/episodes/9). | ||
|
||
Quick Installation | ||
------------------ | ||
Run the following command to install the package through Composer. | ||
``` | ||
composer require srmklive/flash-notifications | ||
``` | ||
|
||
Once this operation is complete, simply add both the service provider and facade classes to your project's `config/app.php` file: | ||
|
||
#### Laravel 5.0.x | ||
##### Service Provider | ||
```php | ||
'Srmklive\FlashAlert\FlashAlertServiceProvider', | ||
``` | ||
|
||
##### Facade | ||
```php | ||
'FlashAlert' => 'Srmklive\FlashAlert\Facades\FlashAlert', | ||
``` | ||
|
||
#### Laravel 5.1.x | ||
##### Service Provider | ||
```php | ||
Srmklive\FlashAlert\FlashAlertServiceProvider::class, | ||
``` | ||
|
||
##### Facade | ||
```php | ||
'FlashAlert' => Srmklive\FlashAlert\Facades\FlashAlert::class, | ||
``` | ||
|
||
#### Publish Configuration | ||
php artisan vendor:publish | ||
|
||
Usage | ||
----- | ||
Usage is simple. Before redirecting to another page, simply call on `FlashAlert` to set your desired flash notification. There are a number of methods to assign different levels of priority (info, success, warning, and error). | ||
|
||
#### Success | ||
|
||
```php | ||
FlashAlert::success('Success', 'This is a success message.'); | ||
``` | ||
|
||
#### Info | ||
|
||
```php | ||
FlashAlert::info('Info', 'This is an info message.'); | ||
``` | ||
|
||
#### Warning | ||
|
||
```php | ||
FlashAlert::warning('Warning', 'This is a warning message.'); | ||
``` | ||
|
||
#### Error | ||
|
||
```php | ||
FlashAlert::error('Error', 'This is an error message.'); | ||
``` | ||
|
||
### Rendering | ||
To render your flash notifications in your view, simply include the view partial in your master layout: | ||
|
||
```php | ||
@include('flashalert::alert') | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "srmklive/flash-notifications", | ||
"type": "library", | ||
"description": "Elegant Flash Notifications For Laravel", | ||
"minimum-stability": "dev", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Raza Mehdi", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"autoload":{ | ||
"psr-4": { | ||
"Srmklive\\FlashAlert\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* FlashAlert Settings | ||
* Created By Raza Mehdi<[email protected]> | ||
*/ | ||
|
||
return [ | ||
|
||
/** | ||
* Setting to determine whether session should be cleared after message is displayed to user. | ||
* Should be either true/false | ||
*/ | ||
|
||
'clear_session' => true, | ||
|
||
/** | ||
* Time after alert message to be hidden. | ||
* For example, if the alert message should be hidden after 2 seconds then the value below should be 2000 | ||
*/ | ||
|
||
'hide_timer' => 1000, | ||
|
||
/** | ||
* Setting to determine whether confirmation button should be shown. | ||
* Should be either true/false | ||
*/ | ||
|
||
'show_confirmation_button' => false, | ||
|
||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php namespace Srmklive\FlashAlert\Facades; | ||
|
||
/** | ||
* Class Facade | ||
* @package Srmklive\FlashAlert\Facades | ||
* @see Srmklive\FlashAlert\FlashAlertHandler | ||
*/ | ||
|
||
use Illuminate\Support\Facades\Facade; | ||
|
||
class FlashAlert extends Facade | ||
{ | ||
/** | ||
* Get the registered name of the component. | ||
* | ||
* @return string | ||
*/ | ||
protected static function getFacadeAccessor() | ||
{ | ||
return 'Srmklive\FlashAlert\FlashAlertHandler'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php namespace Srmklive\FlashAlert; | ||
|
||
|
||
class FlashAlertHandler | ||
{ | ||
/** | ||
* @var SessionStore | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param SessionStore $session | ||
*/ | ||
public function __construct(SessionStore $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Create an info flash message. | ||
* | ||
* @param string $message | ||
*/ | ||
public function info($title, $message) | ||
{ | ||
$this->message($title, $message, 'info'); | ||
} | ||
|
||
/** | ||
* Create a success flash message. | ||
* | ||
* @param string $message | ||
*/ | ||
public function success($title, $message) | ||
{ | ||
$this->message($title, $message, 'success'); | ||
} | ||
|
||
/** | ||
* Create a warning flash message. | ||
* | ||
* @param string $message | ||
*/ | ||
public function warning($title, $message) | ||
{ | ||
$this->message($title, $message, 'warning'); | ||
} | ||
|
||
/** | ||
* Create an error flash message. | ||
* | ||
* @param string $message | ||
*/ | ||
public function error($title, $message) | ||
{ | ||
$this->message($title, $message, 'danger'); | ||
} | ||
|
||
/** | ||
* Create a flash message. | ||
* | ||
* @param string $title | ||
* @param string $message | ||
* @param string $level | ||
*/ | ||
public function message($title, $message, $level = 'info') | ||
{ | ||
$this->session->flash('flashalert.title', $title); | ||
$this->session->flash('flashalert.message', $message); | ||
$this->session->flash('flashalert.level', $level); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php namespace Srmklive\FlashAlert; | ||
|
||
/** | ||
* Class PayPalServiceProvider | ||
* @package Srmklive\FlashAlert | ||
*/ | ||
|
||
use Illuminate\Support\ServiceProvider; | ||
|
||
class FlashAlertServiceProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = false; | ||
|
||
/** | ||
* Bootstrap the application events. | ||
* | ||
* @return void | ||
*/ | ||
public function boot() | ||
{ | ||
// Publish config files | ||
$this->publishes([ | ||
__DIR__. '/../config/config.php' => config_path('flashalert.php'), | ||
]); | ||
|
||
// Load FlashAlert View Files | ||
$this->loadViewsFrom(__DIR__.'/../views', 'flashalert'); | ||
|
||
$this->publishes([ | ||
__DIR__.'/../views' => base_path('resources/views/vendor/flashalert'), | ||
]); | ||
} | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
$this->registerFlashAlert(); | ||
} | ||
|
||
/** | ||
* Register the application bindings. | ||
* | ||
* @return void | ||
*/ | ||
private function registerFlashAlert() | ||
{ | ||
$this->app->bind( | ||
'Srmklive\FlashAlert\SessionStore', | ||
'Srmklive\FlashAlert\FlashAlertSessionStore' | ||
); | ||
|
||
$this->app->bindShared('flashalert', function() { | ||
return $this->app->make('Srmklive\FlashAlert\FlashAlertHandler'); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php namespace Srmklive\FlashAlert; | ||
|
||
use Illuminate\Session\Store; | ||
|
||
class FlashAlertSessionStore implements SessionStore | ||
{ | ||
/** | ||
* @var Store | ||
*/ | ||
private $session; | ||
/** | ||
* @param Store $session | ||
*/ | ||
function __construct(Store $session) | ||
{ | ||
$this->session = $session; | ||
} | ||
/** | ||
* Flash a message to the session. | ||
* | ||
* @param string $name | ||
* @param mixed $data | ||
*/ | ||
public function flash($name, $data) | ||
{ | ||
$this->session->flash($name, $data); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php namespace Srmklive\FlashAlert; | ||
|
||
|
||
interface SessionStore | ||
{ | ||
/** | ||
* Flash a message to the session | ||
* | ||
* @param string $name | ||
* @param mixed $data | ||
*/ | ||
public function flash($name, $data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
@if(session()->has('flashalert')) | ||
|
||
@section('styles') | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" /> | ||
@endsection | ||
|
||
|
||
|
||
@section('scripts') | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script> | ||
<script type="text/javascript"> | ||
swal({ | ||
title: "", | ||
text: "{{{session()->get('flashalert.message')}}}", | ||
type: "{{{session()->get('flashalert.level')}}}", | ||
timer: {{{config('flashalert.hide_timer')}}}, | ||
showConfirmButton: {{{config('flashalert.show_confirmation_button')}}} | ||
}); | ||
</script> | ||
@endsection | ||
|
||
@endif |