diff --git a/app/Http/Livewire/Projected.php b/app/Http/Livewire/Projected.php index b1a92cf..bada99f 100644 --- a/app/Http/Livewire/Projected.php +++ b/app/Http/Livewire/Projected.php @@ -217,25 +217,32 @@ class Projected extends Component })->where("id", $id)->first(); if($post) { - $this->rowPostID = $post->id; - $this->rowName = $post->name; - $this->rowTypeHTML = "is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income").""; - $this->modalRowUpdate = true; + $this->rowPostID = $post->id; + $this->rowName = $post->name; + $this->rowTypeHTML = "is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income").""; + $this->modalRowUpdate = true; $this->emit("focusField", "rowValue"); } } - public function updateRow() { + public function updateRow(): void + { $post = \App\Models\Post::whereHas('category', function ($query) { return $query->where('user_id', \Auth::user()->id); })->where("id", $this->rowPostID)->first(); - $value = null; - if($this->rowValue != null && trim($this->rowValue) != "" && is_numeric(trim($this->rowValue))) { - $value = floatval($this->rowValue); + # edit name + if ($post->name !== $this->rowName) { + $post->update(['name' => $this->rowName]); + $post->save(); } - if($post != null && $value !== null) { + $value = null; + if($this->rowValue !== null && trim($this->rowValue) !== "" && is_numeric(trim($this->rowValue))) { + $value = (float)$this->rowValue; + } + + if($post !== null && $value !== null) { for($m=1;$m<=12;$m++) { $post->setMonthValue($m, $value); } diff --git a/app/Models/Post.php b/app/Models/Post.php index 49d6a8c..4f9f0ba 100644 --- a/app/Models/Post.php +++ b/app/Models/Post.php @@ -10,6 +10,7 @@ class Post extends Model use HasFactory; private $monthValueCache = null; private $monthActualValueCache = null; + protected $guarded = []; public function category() { return $this->belongsTo(\App\Models\Category::class); diff --git a/resources/views/livewire/projected.blade.php b/resources/views/livewire/projected.blade.php index 49c412b..63ecbe9 100644 --- a/resources/views/livewire/projected.blade.php +++ b/resources/views/livewire/projected.blade.php @@ -185,14 +185,14 @@