PHP code example of dvsoftsrl / laravel-attributechangelog

1. Go to this page and download the library: Download dvsoftsrl/laravel-attributechangelog 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/ */

    

dvsoftsrl / laravel-attributechangelog example snippets


return [
    'enabled' => env('ATTRIBUTE_CHANGE_LOGGER_ENABLED', true),
    'attribute_change_log_model' => \DvSoft\AttributeChangeLog\Models\AttributeChangeLog::class,
    'table_name' => env('ATTRIBUTE_CHANGE_TABLE_NAME', 'activity_log'),
    'database_connection' => env('ATTRIBUTE_CHANGE_DB_CONNECTION'),
];

use DvSoft\AttributeChangeLog\Traits\LogsAttributeChange;
use Illuminate\Database\Eloquent\Model;

class MyModel extends Model
{
    use LogsAttributeChange;

    protected $fillable = ['name', 'status'];
}

$myModel = MyModel::find(1);
$myModel->status = 'published';
$myModel->save();

$lastStatusChange = $myModel->attributeChangeLogs()
    ->forAttribute('status')
    ->latest('created_at')
    ->first();

$yesterdayLogs = MyModel::editedAttributeOn('status', today()->subDay())->get();
bash
php artisan vendor:publish --provider="DvSoft\AttributeChangeLog\AttributeChangeLogServiceProvider" --tag="attributechangelog-migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --provider="DvSoft\AttributeChangeLog\AttributeChangeLogServiceProvider" --tag="attributechangelog-config"