Laravel spatie activitylog

  $record = ListBrf::where('department_id', $v)
                                ->latest()->first();
                       

                            activity()
                            ->inLog('logname')
                            ->performedOn($record) // Specify the model related to the activity (optional)
                            ->causedBy(auth()->user()) // Specify the user causing the activity (optional)
                            ->withProperties(['customProperty' => 'customValue']) // Additional details (optional)
                            ->createdAt(now())
                            ->event('verified')
                            ->log('Your custom log message');

    public function setCustomDescription($description)
    {
        $this->customDescription = $description;
    }

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
        ->logOnly(['*'])
        ->useLogName('List BRF')
        ->setDescriptionForEvent(function (string $eventName) {
            // Set a custom description based on the event type
            if($this->step_status){
                return $this->step_status_detail($this->step_status);
            }
            return match ($eventName) {
                'created' => "A new record was created with ID {$this->id}",
                'updated' => "The record with ID {$this->id} was updated",
                'deleted' => "The record with ID {$this->id} was deleted",
                default => "Performed {$eventName} on record with ID {$this->id}"
            };
        });
        
    }
    
    
    
    ///how to use
     $this->setCustomDescription($this->step_status_detail($btu_step_status));

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *