Initial commit
This commit is contained in:
48
app/Http/Requests/SendMoneyRequest.php
Normal file
48
app/Http/Requests/SendMoneyRequest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SendMoneyRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'recipient_email' => [
|
||||
'required',
|
||||
'email',
|
||||
Rule::exists(User::class, 'email')->whereNot('id', $this->user()->id),
|
||||
],
|
||||
'amount' => [
|
||||
'required',
|
||||
'numeric',
|
||||
'min:0.01',
|
||||
],
|
||||
'reason' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getRecipient(): User
|
||||
{
|
||||
return User::where('email', '=', $this->input('recipient_email'))->firstOrFail();
|
||||
}
|
||||
|
||||
public function getAmountInCents(): int
|
||||
{
|
||||
return (int) ceil($this->float('amount') * 100);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user