fix the issue with the previous commit. event was called before the labels attached to a cycle.

This commit is contained in:
Moradi
2025-03-12 16:42:00 +03:30
parent 5fe7474227
commit 034000bcef
3 changed files with 5 additions and 10 deletions
+4
View File
@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Events\CycleSaved;
use App\Http\Requests\StoreCycleRequest;
use App\Http\Resources\CycleResource;
use App\Interfaces\CycleRepositoryInterface;
@@ -72,6 +73,8 @@ class CycleController extends Controller
foreach ( $Labels as $Label => $Count ) {
$CycleObj->labels()->attach( array( $Label ) , [ 'count' => $Count ] );
}
event(new CycleSaved($CycleObj));
return MessageResponse::success( trans( 'messages.success' ) );
}
@@ -109,6 +112,7 @@ class CycleController extends Controller
foreach ( $Labels as $Label => $Count ) {
$Cycle->labels()->attach( array( $Label ) , [ 'count' => $Count ] );
}
event(new CycleSaved($Cycle));
return MessageResponse::success( trans( 'messages.success' ) );
}
@@ -23,6 +23,7 @@ class UpdateLabelsCycleNumber
{
$cycle = $event->cycle;
$cycleNumber = $cycle->cycle_number;
// dd($cycle->labels);
$cycle->labels()->update(['cycle_number' => $cycleNumber]);
}
-10
View File
@@ -15,16 +15,6 @@ class Cycle extends Model
'date', 'user_id', 'cycle_number', 'sterilizer_id', 'note', 'verified', 'unique_id'
];
protected static function booted()
{
static::created(function ($cycle) {
event(new CycleSaved($cycle));
});
static::updated(function ($cycle) {
event(new CycleSaved($cycle));
});
}
public function user(): BelongsTo
{