change strcture controller becuse repet some code in 3 file and get same code in model
This commit is contained in:
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\HarimStates;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class Harim extends Model
|
||||
{
|
||||
@@ -23,4 +26,23 @@ class Harim extends Model
|
||||
get: fn($value) => json_decode($value)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function updateStateWithHistory(int $action, string $description , array $data): void
|
||||
{
|
||||
DB::transaction(function () use ($action, $description, $data) {
|
||||
$this->histories()->create([
|
||||
'expert_id' => auth()->user()->id,
|
||||
'previous_state_id' => $this->state_id,
|
||||
'previous_state_name'=> $this->state_name,
|
||||
'expert_description' => $description,
|
||||
'action_id' => $action,
|
||||
'action_name' => HarimAction::name($action),
|
||||
]);
|
||||
|
||||
$this->update($data);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user