Skip to content

Commit 9d5ed27

Browse files
committed
Custom e-mail view name + Documentation
1 parent 54b81cd commit 9d5ed27

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,16 @@ proper e-mail component configuration.
142142
### E-mail View
143143

144144
The user will receive an e-mail with a link leading to the `getVerification()`
145-
method (endpoint). Create a view for this e-mail at
146-
`resources/views/emails/user-verification.blade.php`. The view will receive the
147-
`$user` variable which contains the user details such as the verification
148-
token. Here is a sample e-mail view content to get you started with:
145+
method (endpoint). The view will receive a `$user` variable which contains the
146+
user details such as the verification token.
147+
148+
By default the package sets the e-mail view as `emails.user-verification`.
149+
Create a view for this e-mail at `resources/views/emails/user-verification.blade.php`.
150+
151+
If you want to customize the e-mail view location you can create the view file
152+
wherever you want and call `UserVerification::viewName('directory.your-view-name')`.
153+
154+
Here is a sample e-mail view content to get you started with:
149155
**The link url must contain the verification token as parameter + (mandatory) a
150156
query string with the user's e-mail as parameter.**
151157

@@ -245,16 +251,12 @@ The package offers a facade `UserVerification::`.
245251
### Attributes/Properties
246252

247253
To customize the package behaviour and the redirects you can implement and
248-
customize six (6) attributes/properties:
254+
customize six (5) attributes/properties:
249255

250256
* `$redirectIfVerified = '/';`
251257

252258
Where to reditect if the authenticated user is already verified.
253259

254-
* `$redirectAfterTokenGeneration = '/';`
255-
256-
Where to redirect after a successful verification token generation.
257-
258260
* `$redirectAfterVerification = '/';`
259261

260262
Where to redirect after a successful verification token verification.

src/Traits/RedirectsUsers.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,6 @@ public function redirectIfVerified()
1818
return property_exists($this, 'redirectIfVerified') ? $this->redirectIfVerified : '/';
1919
}
2020

21-
/**
22-
* Get the redirect path for a successful verification token generation.
23-
*
24-
* @return string
25-
*/
26-
public function redirectAfterTokenGeneration()
27-
{
28-
return property_exists($this, 'redirectAfterTokenGeneration') ? $this->redirectAfterTokenGeneration : '/';
29-
}
30-
3121
/**
3222
* Get the redirect path for a successful verification token verification.
3323
*

src/Traits/VerifiesUsers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ protected function verificationErrorView()
7777
return property_exists($this, 'verificationErrorView') ? $this->verificationErrorView : 'errors.user-verification';
7878
}
7979

80+
/**
81+
* Get the verification e-mail view name.
82+
*
83+
* @return string
84+
*/
85+
protected function verificationEmailView()
86+
{
87+
return property_exists($this, 'verificationEmailView') ? $this->verificationEmailView : 'emails.user-verification';
88+
}
89+
8090
/**
8191
* Get the user table name.
8292
*

src/UserVerification.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ class UserVerification
3232
*/
3333
protected $schema;
3434

35+
/**
36+
* E-mail view name.
37+
*
38+
* @var string
39+
*/
40+
protected $emailView;
41+
3542
/**
3643
* Create a new instance.
3744
*
@@ -41,8 +48,9 @@ class UserVerification
4148
*/
4249
public function __construct(MailerContract $mailer, Builder $schema)
4350
{
44-
$this->mailer = $mailer;
45-
$this->schema = $schema;
51+
$this->mailer = $mailer;
52+
$this->schema = $schema;
53+
$this->emailView = 'emails.user-verification';
4654
}
4755

4856
/**
@@ -108,6 +116,19 @@ public function send(AuthenticatableContract $user, $subject = null, $from = nul
108116
return (boolean) $this->emailVerificationLink($user, $subject, $from, $name);
109117
}
110118

119+
/**
120+
* Set the e-mail view name.
121+
*
122+
* @param mixed $name
123+
* @return \Jrean\UserVerification
124+
*/
125+
public function emailView($name)
126+
{
127+
$this->emailView = $name;
128+
129+
return $this;
130+
}
131+
111132
/**
112133
* Process the user verification for the given e-mail and token.
113134
*
@@ -224,7 +245,7 @@ protected function updateUser($user)
224245
*/
225246
protected function emailVerificationLink(AuthenticatableContract $user, $subject, $from = null, $name = null)
226247
{
227-
return $this->mailer->send('emails.user-verification', compact('user'), function ($m) use ($user, $subject, $from, $name) {
248+
return $this->mailer->send($this->emailView, compact('user'), function ($m) use ($user, $subject, $from, $name) {
228249
if (! empty($from)) {
229250
$m->from($from, $name);
230251
}

0 commit comments

Comments
 (0)