PHP code example of ohkannaduh / laravel-change-logger
1. Go to this page and download the library: Download ohkannaduh/laravel-change-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/ */
ohkannaduh / laravel-change-logger example snippets
namespace App\Models;
use OhKannaDuh\ChangeLogger\Models\Behaviours\LogsChanges;
final class SomeModel extends Model
{
use LogsChanges;
...
}
namespace App\Models;
use OhKannaDuh\ChangeLogger\Models\Behaviours\LogsChanges;
final class SomeModel extends Model
{
use LogsChanges;
...
/** string[] */
protected $observedAttributes = [
'name',
'password',
];
}
...
/** @var SomeModel $someModel */
$someModel->update([
'name' => 'Luigi',
'country' => 'The Mushroom Kingdom',
]);
// Only name will be shown in logs, the country attribute is not being observed
namespace App\Models;
use OhKannaDuh\ChangeLogger\Models\Behaviours\LogsChanges;
final class SomeModel extends Model
{
use LogsChanges;
...
/** string[] */
protected $withoutAttributes = [
'name',
];
}
...
/** @var SomeModel $someModel */
$someModel->update([
'name' => 'Luigi',
'country' => 'The Mushroom Kingdom',
]);
// the name attribute will be removed from the log as it is declared in $withoutAttributes
namespace App\Models;
use OhKannaDuh\ChangeLogger\Models\Behaviours\LogsChanges;
final class SomeModel extends Model
{
use LogsChanges;
...
/** string[] */
protected $obfuscateAttributes = [
'password',
];
}
...
/** @var SomeModel $someModel */
$someModel->update([
'name' => 'Luigi',
'password' => 'secret',
]);
// the password attribute will be replaced in the logged output by a random string, now we can track that it changed but
// not log the value