Skip to content

Commit

Permalink
fix issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrouh committed Nov 12, 2022
1 parent 98b6e71 commit d4f5b74
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/Traits/ActivityModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,46 @@ public static function bootActivityModel()
{
if (auth()->user()) {
try {
$user_id = auth()->user()->id;
static::created(function ($model) use ($user_id) {
if ($model->activityDefault()['created']) {
$activity = $model->activities()->create($model->activityDefault()['created'] + ['user_id' => $user_id]);
static::created(function ($model) {
if (array_key_exists('created', $model->activityDefault())) {
$activity = $model->activities()->create($model->activityDefault()['created'] + ['user_id' => auth()->user()->id]);
$model->sendNotification($activity);
}
});

static::deleted(function ($model) use ($user_id) {
if ($model->activityDefault()['deleted']) {
$activity = $model->activities()->create($model->activityDefault()['deleted'] + ['user_id' => $user_id]);
static::deleted(function ($model) {
if (array_key_exists('deleted', $model->activityDefault())) {
$activity = $model->activities()->create($model->activityDefault()['deleted'] + ['user_id' => auth()->user()->id]);
$model->sendNotification($activity);
}
});

static::updated(function ($model) use ($user_id) {
static::updated(function ($model) {
$changes = $model->getChanges();
if (count($changes) > 1 && $model->activityChanges()) {
foreach ($changes as $key => $value) {
if (array_key_exists($key, $model->activityChanges()) && array_key_exists('title_ar', $model->activityChanges()[$key])) {
$activity = $model->activities()->create($model->activityChanges()[$key] + ['user_id' => $user_id]);
$activity = $model->activities()->create($model->activityChanges()[$key] + ['user_id' => auth()->user()->id]);
$model->sendNotification($activity);
} else {
if (array_key_exists($key, $model->activityChanges()) && array_key_exists($value, $model->activityChanges()[$key]) && array_key_exists('title_ar', $model->activityChanges()[$key][$value])) {
$activity = $model->activities()->create($model->activityChanges()[$key][$value] + ['user_id' => $user_id]);
$activity = $model->activities()->create($model->activityChanges()[$key][$value] + ['user_id' => auth()->user()->id]);
$model->sendNotification($activity);
}
}
}
} else {
if ($model->activityDefault()['updated']) {
$activity = $model->activities()->create($model->activityDefault()['updated'] + ['user_id' => $user_id, 'data' => json_encode($model->getChanges())]);
if (array_key_exists('updated', $model->activityDefault())) {
$activity = $model->activities()->create($model->activityDefault()['updated'] + ['user_id' => auth()->user()->id]);
$model->sendNotification($activity);
}
}
});
if (in_array('Illuminate\Database\Eloquent\SoftDeletes', class_uses(new self))) {
static::restored(function ($model) use ($user_id) {
if ($model->activityDefault()['restored']) {
$activity = $model->activities()->create($model->activityDefault()['restored'] + ['user_id' => $user_id]);
$model->sendNotification($activity);
static::restored(function ($model) {
if (array_key_exists('restored', $model->activityDefault())) {
$activity = $model->activities()->create($model->activityDefault()['restored'] + ['user_id' => auth()->user()->id]);
$model->sendNotification($activity);
}
});
}
Expand Down Expand Up @@ -97,7 +96,7 @@ public function sendNotification($activity)
$option = $optionBuilder->build();
$notification = $notificationBuilder->build();
$data = $dataBuilder->build();
$tokens = $this->ActivityFcmUsers();
$tokens = $this->activityFcmTokens();

if (count($tokens) > 0) {
FCM::sendTo($tokens, $option, $notification, $data);
Expand Down

0 comments on commit d4f5b74

Please sign in to comment.