/
FlashNotifier.php
121 lines (102 loc) · 2.25 KB
/
FlashNotifier.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
namespace Laracasts\Flash;
class FlashNotifier
{
/**
* The session writer.
*
* @var SessionStore
*/
private $session;
/**
* Create a new flash notifier instance.
*
* @param SessionStore $session
*/
function __construct(SessionStore $session)
{
$this->session = $session;
}
/**
* Flash an information message.
*
* @param string $message
* @return $this
*/
public function info($message)
{
$this->message($message, 'info');
return $this;
}
/**
* Flash a success message.
*
* @param string $message
* @return $this
*/
public function success($message)
{
$this->message($message, 'success');
return $this;
}
/**
* Flash an error message.
*
* @param string $message
* @return $this
*/
public function error($message)
{
$this->message($message, 'danger');
return $this;
}
/**
* Flash a warning message.
*
* @param string $message
* @return $this
*/
public function warning($message)
{
$this->message($message, 'warning');
return $this;
}
/**
* Flash an overlay modal.
*
* @param string $message
* @param string $title
* @param string $level
* @return $this
*/
public function overlay($message, $title = 'Notice', $level = 'info')
{
$this->message($message, $level);
$this->session->flash('flash_notification.overlay', true);
$this->session->flash('flash_notification.title', $title);
return $this;
}
/**
* Flash a general message.
*
* @param string $message
* @param string $level
* @return $this
*/
public function message($message, $level = 'info')
{
$this->session->flash('flash_notification.message', $message);
$this->session->flash('flash_notification.level', $level);
return $this;
}
/**
* Add an "important" flash to the session.
*
* @return $this
*/
public function important()
{
$this->session->flash('flash_notification.important', true);
return $this;
}
}