Skip to content

Commit 108e2c5

Browse files
committed
Merge branch 'master' of github.com:odannyc/laravel-alertify
2 parents dcb1da3 + 67ae234 commit 108e2c5

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

README.md

+97
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,99 @@
11
# laravel-alertify
22
An alertify package for Laravel
3+
4+
## Installation
5+
This package uses composer, so require it like so:
6+
```
7+
composer require odannyc/laravel-alertify
8+
```
9+
10+
You'll also need to pull in the `alertify.js` project. This is located here: https://alertifyjs.org/
11+
12+
You can use NPM:
13+
```
14+
npm install --save alertify.js
15+
```
16+
17+
Or include the CDN version of it in your `app.blade.php` template. (File may vary on your Laravel installation):
18+
```html
19+
<script src="https://cdn.rawgit.com/alertifyjs/alertify.js/v1.0.10/dist/js/alertify.js"></script>
20+
```
21+
22+
Then, in the template of your Laravel installation, include the view anywhere in the body of your HTML:
23+
```php
24+
@include('alertify::alertify')
25+
```
26+
27+
## Usage
28+
**Make sure you include `alertify.js` prior to using this package. (See installation instructions above)**
29+
30+
You can call the `alertify()` helper function before returning/redirecting to a view:
31+
32+
```php
33+
/**
34+
* Update the specified resource in storage.
35+
*
36+
* @param \Illuminate\Http\Request $request
37+
* @return \Illuminate\Http\Response
38+
*/
39+
public function update(Request $request)
40+
{
41+
alertify()->success('Updated record successfully');
42+
43+
// You can also add multiple alerts!
44+
alertify('You are awesome!');
45+
46+
return redirect()->back();
47+
}
48+
```
49+
50+
You can either use the `alertify()` helper or use the static Facade:
51+
```php
52+
Alertify::standard('I like alerts')
53+
```
54+
55+
There are 3 types of alerts:
56+
```php
57+
alertify('this is a standard alert (shows black)');
58+
alertify()->success('this is a success alert (shows green)');
59+
alertify()->error('this is an error alert (shows red)');
60+
```
61+
62+
You can also show multiple alerts by calling that function multiple times:
63+
```php
64+
alertify('alert 1');
65+
alertify('alert 2');
66+
```
67+
68+
You can save the alert and edit it based on logic:
69+
```php
70+
$alert = alertify('i am an alert');
71+
if ($error) {
72+
$alert->error();
73+
} else {
74+
$alert->success();
75+
}
76+
```
77+
78+
There's many options you can add per alert:
79+
```php
80+
// Show the alert for 5000 milliseconds and then dismisses itself (default: 4000)
81+
alert('delayed 5 seconds')->delay(5000);
82+
83+
// Alert stays displayed with no timeout
84+
alert('i stay displayed on the screen')->persistent();
85+
86+
// Alert can be clicked to be dismissed
87+
alert('i can be clicked to be dismissed')->clickToClose();
88+
89+
// You can position alerts (default: 'top right')
90+
alert('i am on the bottom left')->position('bottom left');
91+
92+
// You can attach the alert to some other HTML element (default: 'document.body')
93+
alert('i am displayed on a different parent')->attach('.some-html-accessor')
94+
```
95+
96+
You can also daisy chain options:
97+
```php
98+
alert()->success('i am daisychained')->delay(10000)->clickToClose()->position('bottom right');
99+
```

0 commit comments

Comments
 (0)