Skip to content

Commit a6268f7

Browse files
committed
Email Register and AfterCheckout
1 parent 2106866 commit a6268f7

File tree

8 files changed

+134
-5
lines changed

8 files changed

+134
-5
lines changed

app/Http/Controllers/User/CheckoutController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use App\Http\Controllers\Controller;
99
use App\Http\Requests\User\Checkout\Store;
1010
use Auth;
11+
use Mail;
12+
use App\Mail\Checkout\AfterCheckout;
1113

1214
class CheckoutController extends Controller
1315
{
@@ -62,6 +64,9 @@ public function store(Store $request, Camp $camp)
6264
// create checkout
6365
$checkout = Checkout::create($data);
6466

67+
// Setting Email
68+
Mail::to(Auth::user()->email)->send(new AfterCheckout($checkout));
69+
6570
return redirect(route('checkout.success'));
6671
}
6772

@@ -120,4 +125,9 @@ public function success(Checkout $checkout)
120125
{
121126
return view('checkout.success');
122127
}
128+
129+
public function invoice(Checkout $checkout)
130+
{
131+
return $checkout;
132+
}
123133
}

app/Http/Controllers/UserController.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Laravel\Socialite\Facades\Socialite;
77
use App\Models\User;
88
use Auth;
9+
use Mail;
10+
use App\Mail\User\AfterRegister;
911

1012
class UserController extends Controller
1113
{
@@ -29,11 +31,14 @@ public function handleProviderCallback()
2931
'email_verified_at' => date('Y-m-d H:i:s', time())
3032
];
3133

32-
$user = User::firstOrCreate(
33-
[
34-
'email' => $data['email']
35-
], $data);
36-
Auth::login($user, true);
34+
// $user = User::firstOrCreate(['email' => $data['email']], $data);
35+
$user = User::whereEmail($data['email'])->first();
36+
if(!$user){
37+
$user = User::create($data);
38+
Mail::to($user->email)->send(new AfterRegister($user));
39+
}
40+
41+
Auth::login($user, true);
3742

3843
return redirect(route('welcome'));
3944
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Mail\Checkout;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Mail\Mailable;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class AfterCheckout extends Mailable
11+
{
12+
use Queueable, SerializesModels;
13+
14+
private $checkout;
15+
16+
/**
17+
* Create a new message instance.
18+
*
19+
* @return void
20+
*/
21+
public function __construct($checkout)
22+
{
23+
$this->checkout =$checkout;
24+
}
25+
26+
/**
27+
* Build the message.
28+
*
29+
* @return $this
30+
*/
31+
public function build()
32+
{
33+
return $this->subject("Register Camp: {$this->checkout->Camp->title}")->markdown('emails.checkout.afterCheckout',[
34+
'checkout' => $this->checkout
35+
]);
36+
}
37+
}

app/Mail/User/AfterRegister.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace App\Mail\User;
4+
5+
use Illuminate\Bus\Queueable;
6+
use Illuminate\Contracts\Queue\ShouldQueue;
7+
use Illuminate\Mail\Mailable;
8+
use Illuminate\Queue\SerializesModels;
9+
10+
class AfterRegister extends Mailable
11+
{
12+
use Queueable, SerializesModels;
13+
14+
private $user;
15+
16+
/**
17+
* Create a new message instance.
18+
*
19+
* @return void
20+
*/
21+
public function __construct($user)
22+
{
23+
$this->user = $user;
24+
}
25+
26+
/**
27+
* Build the message.
28+
*
29+
* @return $this
30+
*/
31+
public function build()
32+
{
33+
return $this->subject('Registration on CourseCast')->markdown('emails.user.afterRegister', [
34+
'user' => $this->user
35+
]);
36+
}
37+
}

app/Models/Checkout.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,15 @@ public function Camp(): BelongsTo
3434
{
3535
return $this->belongsTo(Camp::class);
3636
}
37+
38+
/**
39+
* Get the Camp that owns the Checkout
40+
*
41+
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
42+
*/
43+
public function User(): BelongsTo
44+
{
45+
return $this->belongsTo(User::class);
46+
}
47+
3748
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@component('mail::message')
2+
Register Camp: {{$checkout->Camp->title}}
3+
4+
Hi {{$checkout->User->name}}
5+
<br>
6+
Thank you for register on <b>{{$checkout->Camp->title}}</b>, please see payment instruction by clic the button below.
7+
8+
@component('mail::button', ['url' => route('user.checkout.invoice', $checkout->id)])
9+
Get Invoice
10+
@endcomponent
11+
12+
Thanks,<br>
13+
{{ config('app.name') }}
14+
@endcomponent
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@component('mail::message')
2+
Welcome!
3+
4+
Hi {{$user->name}}!
5+
<br>
6+
Welcome to CourseCast, your account has been created successfully!
7+
8+
@component('mail::button', ['url' => route('login')])
9+
Get Started
10+
@endcomponent
11+
12+
Thanks,<br>
13+
{{ config('app.name') }}
14+
@endcomponent

routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
//
4141
Route::get('dashboard', [HomeController::class, 'dashboard'])->name('dashboard');
42+
Route::get('dashboard/checkout/invoice/{checkout}', [CheckoutController::class, 'invoice'])->name('user.checkout.invoice');
4243
});
4344

4445
require __DIR__.'/auth.php';

0 commit comments

Comments
 (0)