상속: extends Illuminate\Support\ServiceProvider
 public function handle()
 {
     $this->comment('Cleaning activity log...');
     $maxAgeInDays = config('laravel-activitylog.delete_records_older_than_days');
     $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s');
     $activity = ActivitylogServiceProvider::getActivityModelInstance();
     $amountDeleted = $activity::where('created_at', '<', $cutOffDate)->delete();
     $this->info("Deleted {$amountDeleted} record(s) from the activity log.");
     $this->comment('All done!');
 }
예제 #2
0
 public function activity() : MorphMany
 {
     return $this->morphMany(ActivitylogServiceProvider::determineActivityModel(), 'subject');
 }
예제 #3
0
 /**
  * @param string $description
  *
  * @return null|mixed
  */
 public function log(string $description)
 {
     if (!$this->logEnabled) {
         return;
     }
     $activity = ActivitylogServiceProvider::getActivityModelInstance();
     if ($this->performedOn) {
         $activity->subject()->associate($this->performedOn);
     }
     if ($this->causedBy) {
         $activity->causer()->associate($this->causedBy);
     }
     $activity->properties = $this->properties;
     $activity->description = $this->replacePlaceholders($description, $activity);
     $activity->log_name = $this->logName;
     $activity->save();
     return $activity;
 }