1. Go to this page and download the library: Download sourcetoad/logger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Illuminate\Database\Eloquent\Model;
use Sourcetoad\Logger\Contracts\Trackable as TrackableContract;
use Sourcetoad\Logger\Traits\Trackable;
class TrackedModel extends Model implements TrackableContract {
use Trackable;
// Tracked models must implement these functions
public function getOwnerRelationshipName(): ?string
{
//
}
public function trackableOwnerResolver(): ?Model
{
//
}
}
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Collection;
use Sourcetoad\Logger\Contracts\Trackable as TrackableContract;
use Sourcetoad\Logger\Models\AuditChange;
use Sourcetoad\Logger\Models\AuditModel;
use Sourcetoad\Logger\Models\Relations\LoggerMorphMany;
use Sourcetoad\Logger\Traits\Trackable;
use Sourcetoad\Logger\Traits\HasLoggerRelationships;
/**
* @property-read Collection<int, AuditChange> $auditChanges
* @property-read Collection<int, AuditModel> $auditModels
*/
class TrackedModel extends Model implements TrackableContract {
use Trackable;
use HasLoggerRelationships;
/**
* Collection of mutation logs of this model
*
* @return LoggerMorphMany<AuditChange>
*/
public function auditChanges(): LoggerMorphMany
{
return $this->loggerMorphMany(AuditChange::class, 'entity');
}
/**
* Collection of access logs of this model
*
* @return LoggerMorphMany<AuditModel>
*/
public function auditModels(): LoggerMorphMany
{
return $this->loggerMorphMany(AuditModel::class, 'entity');
}
}
public function getOwnerRelationshipName(): string
{
return 'object.relation.owner';
}
public function trackableOwnerResolver(): Owner
{
return $this->object->relation->owner;
}
public function getOwnerRelationshipName(): null
{
return null;
}
public function trackableOwnerResolver(): TrackedModel
{
return $this;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.