Lae/app/Models/PersonalAccessToken.php

33 lines
908 B
PHP
Raw Normal View History

2022-11-07 04:37:54 +00:00
<?php
namespace App\Models;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Laravel\Sanctum\PersonalAccessToken as SanctumPersonalAccessToken;
class PersonalAccessToken extends SanctumPersonalAccessToken
{
use Cachable;
/**
* Limit saving of PersonalAccessToken records
*
* We only want to actually save when there is something other than
* the last_used_at column that has changed. It prevents extra DB writes
* since we aren't going to use that column for anything.
*
2023-02-07 09:04:11 +00:00
* @param array $options
2022-11-07 04:37:54 +00:00
* @return bool
*/
2023-01-10 13:42:27 +00:00
public function save(array $options = []): bool
2022-11-07 04:37:54 +00:00
{
$changes = $this->getDirty();
// Check for 2 changed values because one is always the updated_at column
2023-02-07 09:04:11 +00:00
if (! array_key_exists('last_used_at', $changes) || count($changes) > 2) {
2022-11-07 04:37:54 +00:00
parent::save();
}
2023-01-30 16:14:07 +00:00
2022-11-07 04:37:54 +00:00
return false;
}
}