Skip to content

Commit

Permalink
activitylog example model integrated
Browse files Browse the repository at this point in the history
  • Loading branch information
Raza9798 committed Jun 17, 2024
1 parent b3e18df commit 7a83272
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/Controller/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function setup(){
$this->createTraitsDirectory();
$this->createActivityLogTrait();
$this->publishActivityLogAssets();
$this->createExampleModel();
$this->runActivityLoggerMigrations();

}
Expand All @@ -38,6 +39,18 @@ protected function createActivityLogTrait(){
}
}

protected function createExampleModel(){
$stubPath = dirname(__DIR__, 2) . '/src/stubs/models/HasActivityExample.stub';
$modelPath = app_path('Models/HasActivityExample.php');
$stubContent = File::get($stubPath);
if (!File::exists($modelPath)) {
File::put($modelPath, $stubContent);
}
else{
(new Banner())->warn('HasActivityExample already exists');
}
}

protected function publishActivityLogAssets(){
Artisan::call('vendor:publish', [
'--provider' => 'Spatie\Activitylog\ActivitylogServiceProvider',
Expand Down
3 changes: 2 additions & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

class Config
{
const VERSION = '1.8.2';
const VERSION = '1.8.3';

}
27 changes: 27 additions & 0 deletions src/stubs/models/HasActivityExample.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Models;

use App\Traits\HasActivityLog;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class HasActivityExample extends Model
{
use HasFactory, HasActivityLog;

public $activity_module = 'HasActivityExample';
public $activity_column = 'name';

protected $fillable = ['name', 'email', 'payment_method', 'amount'];

/**
* ACTIVITY LOG DESCRIPTION FOR THIS MODEL
*/
public function activityInfo(){
return [
"activity_column" => $this->name,
"activity_description" => "{$this->payment_method} of {$this->amount} rupees"
];
}
}

0 comments on commit 7a83272

Please sign in to comment.