global progress
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\Rules;
|
||||
use Illuminate\View\View;
|
||||
@@ -28,11 +29,19 @@ class RegisteredUserController
|
||||
'password' => ['required', 'confirmed', Rules\Password::defaults()],
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => strtolower($request->email),
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
$user = DB::transaction(function () use ($request) {
|
||||
$user = User::create([
|
||||
'name' => $request->name,
|
||||
'email' => strtolower($request->email),
|
||||
'password' => Hash::make($request->password),
|
||||
]);
|
||||
|
||||
$user->wallet()->create([
|
||||
'balance' => 0,
|
||||
]);
|
||||
|
||||
return $user;
|
||||
});
|
||||
|
||||
event(new Registered($user));
|
||||
|
||||
|
@@ -10,6 +10,14 @@ class DashboardController
|
||||
{
|
||||
public function __invoke(Request $request)
|
||||
{
|
||||
$wallet = $request->user()->wallet;
|
||||
|
||||
// bouger cette partie dans un service ou un listener quand on aura le temps, ainsi que le même code dans l'inscription
|
||||
if (! $wallet) {
|
||||
$request->user()->wallet()->create(['balance' => 0]);
|
||||
$request->user()->load('wallet');
|
||||
}
|
||||
|
||||
$transactions = $request->user()->wallet->transactions()->with('transfer')->orderByDesc('id')->get();
|
||||
$balance = $request->user()->wallet->balance;
|
||||
|
||||
|
10
app/Models/RecuringTransfer.php
Executable file
10
app/Models/RecuringTransfer.php
Executable file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RecuringTransfer extends Model
|
||||
{
|
||||
//
|
||||
}
|
55
app/Notifications/WalletBalanceLowNotification.php
Executable file
55
app/Notifications/WalletBalanceLowNotification.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class WalletBalanceLowNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
/**
|
||||
* Create a new notification instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the notification's delivery channels.
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*/
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
return (new MailMessage)
|
||||
->line('Your balance of your wallet is low.')
|
||||
->action('see your dashboard', route('dashboard'))
|
||||
->line('Thank you for using our application!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
20
app/Observers/WalletObserver.php
Executable file
20
app/Observers/WalletObserver.php
Executable file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Observers;
|
||||
|
||||
use App\Models\Wallet;
|
||||
use App\Notifications\WalletBalanceLowNotification;
|
||||
|
||||
class WalletObserver
|
||||
{
|
||||
public function updated(Wallet $wallet)
|
||||
{
|
||||
// todo mettre le montant dans un fichier de config / une constante ou autre
|
||||
// /!\ balance is in cents
|
||||
if ($wallet->getOriginal('balance') > $wallet->balance && $wallet->balance < 1000) {
|
||||
$wallet->user->notify(new WalletBalanceLowNotification($wallet));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user