MedicOneSystems / MedicOneSystems/livewire-datatables

Automatically update one column when another is edited

Open
#569 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
1.2k
Forks
257
PR merge metrics
No merged PRs in 30d

Description

I have two columns 'rate' and 'total' in my model and my Datatable has the following columns

NumberColumn::name('rate')->label('Rate)')->editable(),
NumberColumn::name('total')->label('Total')->editable(),

I need total to be automatically updated when I update the rate value. Normally I'd achieve that from my Eloquent model like this

---Model.php

protected static function boot()
    {
        parent::boot();

        self::updating(function($model){ 
            $model->total = $model->rate //(or some similar logic)
}

This works when I do a manual update of the model from my other view but when I use the Livewire datatable, the update doesn't take place on the 'total' column. Any ideas how to work around this?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Model.php updating callback and trace how edits from the Livewire datatable are persisted through Eloquent. Verify whether the callback runs for inline edits, then ensure a rate change also results in the expected total value; no test or specific repository entry point is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.