Skip to content

Commit

Permalink
fix(core): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
hsbmaulana committed Nov 14, 2023
1 parent 846d22b commit 0bc6572
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 251 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ php artisan vendor:publish --tag=tripteki-laravelphp-log-migrations
$ php artisan migrate
```

- Emit Event-Listener.

```
php artisan queue:work
```

- Publish tests file into your project's directory with running (optionally) :

```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tripteki/laravelphp-log",
"version": "1.0.0",
"version": "1.0.1",
"description": "Trip Teknologi's Laravel.php Logs",

"readme": "README.md",
Expand Down
40 changes: 0 additions & 40 deletions src/Events/Logs/Any.php

This file was deleted.

40 changes: 0 additions & 40 deletions src/Events/Logs/Update.php

This file was deleted.

79 changes: 0 additions & 79 deletions src/Listeners/Logs/AnyListener.php

This file was deleted.

41 changes: 0 additions & 41 deletions src/Listeners/Logs/UpdateListener.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Providers/LogServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

namespace Tripteki\Log\Providers;

use Tripteki\Log\Events\Logs\Update;
use Tripteki\Log\Events\Logs\Any;
use Tripteki\Log\Listeners\Logs\UpdateListener;
use Tripteki\Log\Listeners\Logs\AnyListener;
use Tripteki\Log\Models\Admin\Log;
use Tripteki\Uid\Observers\UniqueIdObserver;
use Tripteki\Log\Console\Commands\InstallCommand;
use Tripteki\Repository\Providers\RepositoryServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Event;

class LogServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -174,8 +169,5 @@ protected function registerPublishers()
public function dataEventListener()
{
Log::observe(UniqueIdObserver::class);

Event::listen(Update::class, [ UpdateListener::class, "handle", ]);
Event::listen(Any::class, [ AnyListener::class, "handle", ]);
}
};
42 changes: 6 additions & 36 deletions src/Traits/LogTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,26 @@

namespace Tripteki\Log\Traits;

use Tripteki\Log\Events\Logs\Update;
use Tripteki\Log\Events\Logs\Any;
use Illuminate\Support\Str;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Activitylog\LogOptions;
use Illuminate\Database\Eloquent\Model;

trait LogTrait
{
use LogsActivity;

/**
* @return void
*/
protected static function bootLogsActivity(): void
{
$class = static::class;

static::eventsToBeRecorded()->each(function ($event) use ($class) {

if ($event === "updated") {

static::updating(function (Model $model) use ($event, $class) {

event(new Update($event, $class, $model));
});
}

static::$event(function (Model $model) use ($event, $class) {

event(new Any($event, $class, $model));
});
});
}

/**
* @return array
*/
public static function changesPipes(): array
{
return static::$changesPipes;
}

/**
* @return \Spatie\Activitylog\LogOptions
*/
public function getActivitylogOptions(): LogOptions
{
$log = LogOptions::defaults()
->logOnlyDirty()
->useLogName(isset(static::$recordName) ? static::$recordName : get_class($this));
->useLogName(isset(static::$recordName) ? static::$recordName : Str::beforeLast(get_class($this), "\\"))
->setDescriptionForEvent(function ($event) {

return get_class($this).".".$event.".".$this->{$this->getKeyName()};
});

if (isset(static::$recordLists)) {

Expand Down

0 comments on commit 0bc6572

Please sign in to comment.