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
//! Notify users by email, text message, Slack, and package [channels](Channel).
//!
//! When something happens that a user should hear about, such as a paid invoice, a notification
//! tells them on each channel they use. A notification is a struct with [`#[notification]`](macro@crate::notification) on the impl
//! holding its `mail`, `sms`, `slack`, and `#[via(Channel)]` methods. The attribute implements
//! [`Notification`], [`ToMail`], [`ToSms`], and [`ToChannel`] from them. `notification::to`
//! names the notifiables, and `send` or `queue` delivers the notification to each of them:
//!
//! ```no_run
//! use laravel::mail::{Address, Mailable};
//! use laravel::notification;
//! use laravel::notification::{ReceivesMail, ReceivesSms};
//! use laravel::sms::PhoneNumber;
//!
//! pub struct User { pub name: String, pub email: String, pub phone: Option<String> }
//!
//! impl ReceivesMail for User {
//! fn mail_address(&self) -> Option<Address> {
//! Some(Address::new(&self.email).with_name(&self.name))
//! }
//! }
//!
//! impl ReceivesSms for User {
//! fn sms_number(&self) -> Option<PhoneNumber> {
//! self.phone.as_deref().map(PhoneNumber::new)
//! }
//! }
//!
//! #[derive(Mailable)]
//! #[mail(subject = "Invoice #{invoice_id} is paid")]
//! pub struct InvoicePaidEmail { pub name: String, pub invoice_id: u64 }
//!
//! pub struct InvoicePaid { pub invoice_id: u64 }
//!
//! #[notification]
//! impl InvoicePaid {
//! fn mail(&self, user: &User) -> impl Mailable {
//! InvoicePaidEmail { name: user.name.clone(), invoice_id: self.invoice_id }
//! }
//!
//! fn sms(&self, _user: &User) -> String {
//! format!("Invoice #{} is paid.", self.invoice_id)
//! }
//! }
//!
//! # async fn example(user: User, team: Vec<User>) -> laravel::Result<()> {
//! notification::to(&user).send(InvoicePaid { invoice_id: 42 }).await?;
//! notification::to(&team).queue(InvoicePaid { invoice_id: 42 }).await?;
//! # Ok(()) }
//! ```
//!
//! A method that can fail to build its message, such as one that links to a route, returns a
//! `laravel::Result` of it instead. The traits always return a `Result`, and the attribute wraps
//! the message of a method that doesn't. The [notifications guide] covers notifiables, choosing
//! channels for each notifiable, package channels, and testing with [`fake`](fake()).
//!
//! [notifications guide]: https://github.com/laravel/rust-framework/blob/0.x/docs/notifications.md
pub use __Deliver;
pub use *;
pub use ;