Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ene's avatar
Level 2

withdraw deduction

i have a withdraw model and point model both have relationship to users , i will like when a user fill the withdrawal form by inserting the amount they will like to request i want deduct the user point when the point is been submitted

how will i do this please i will love your help

class RequestWithdraw extends Component
{

    public $withdraw;
    public $showModal = false;
    public $withdrawId;
    public $image;

    protected $rules = [
        'withdraw.bank' => '',
        'withdraw.account_name' => '',
        'withdraw.account_number' => '',
        'withdraw.amount' => '',
    ];


    public function edit($withdrawId)
    {
        // $this->showModal = true;
        $this->withdrawId = $withdrawId;
        $this->withdraw = Withdraw::find($withdrawId);
    }

    public function create()
    {
        // $this->showModal = true;
        $this->withdraw = null;
        $this->withdrawId = null;
    }

    // public function save()
    // {
    //     $this->validate([
    //         'image' => 'image|max:1024', // 1MB Max
    //     ]);


    //     if (!is_null($this->withdrawId)) {
    //         $path = $this->image->storeAs('withdraw', str::random(30));
    //         $this->withdraw->image = $path;
    //         $this->withdraw->save();
    //     }

    //     $this->showModal = false;
    // }

    // public function close()
    // {
    //     $this->showModal = false;
    // }

    public function render()
    {
        $users = Withdraw::with(['user'])->where('user_id', auth()->user()->id)->get();
        return view('livewire.user.request-withdraw',[
            'users' => $users,
        ]);
    }
}
0 likes
6 replies
tykus's avatar

@ene your description of the problem is too vague to give you appropriate suggestions; please expand.

ene's avatar
Level 2

@tykus ok

every month users must accumulate up to 5000point or more , when the user has reached the minimum threshold a withdraw form appears now the user input the amount they will like to withdraw after the withdraw form has been submitted successfully the user point ( the amount the user request ) get deducted from the user point model automatically

how can i create this functionality

tykus's avatar

@ene still it is not entirely clear...

i want deduct the user point when the point is been submitted

after the withdraw form has been submitted successfully the user point ( the amount the user request ) get deducted from the user point model automatically

What data determines how many points are deducted???

ene's avatar
Level 2

@tykus the withdraw table has amount field that's is supposed to determine the total amount of points to be deducted from the user point

tykus's avatar
tykus
Best Answer
Level 104

@ene I guess I don't understand why is there a Withdraw model at all?

Anyway using Model events, you can hook into the created event on a Withdraw model and update the Point model from there. There are a number of ways to hook into this event; check out the documentation for Model Events, and Observers. The simplest way is a Closure on the Withdraw model, e.g.

public static function booted()
{
    static::created(function ($withdraw) {
        Point::where('user_id', $withdraw->user_id)->decrement('points', $withdraw->amount);
    });
}

So, this is assuming there is one Point record for each user, and you are decrementing the points property by the amount.

Please or to participate in this conversation.