File: /home/armgroup/libs/app/Http/Livewire/Admin/Wallet/Create.php
<?php
namespace App\Http\Livewire\Admin\Wallet;
use App\Http\Livewire\ConvertEmptyStringsToNull;
use App\Http\Livewire\General;
use App\Models\User;
use App\Models\Wallet;
use Livewire\Component;
class Create extends Component
{
use ConvertEmptyStringsToNull, General;
public User $user;
public $amount;
public $description;
public $type = 1;
public function render()
{
return view('livewire.admin.wallet.create');
}
protected function rules()
{
return [
'description' => 'required|string|max:60000',
'type' => 'required|boolean',
'amount' => ['required', 'integer', 'min:1', 'max:100000000000', function ($attribute, $value, $fail) {
if (! $this->type && $this->user->credit < $value) {
return $fail('مقدار کاهشی باید کمتر یا مساوی اعتبار فعلی کاربر باشد.');
}
}],
];
}
public function store()
{
$this->validate();
$wallet = Wallet::create([
'user_id' => $this->user->id,
'amount' => $this->type ? $this->amount : $this->amount * -1,
'description' => $this->description,
'walletable_id' => auth()->id(),
'walletable_type' => User::class,
]);
saveActivity("یک مورد جدید به کیفپول {$this->user->name} اضافه کرد", $wallet);
$this->doneMessage();
return redirect()->route('admin.user.wallet.index', $this->user);
}
}