改进 模型

This commit is contained in:
iVampireSP.com 2022-11-07 12:37:54 +08:00
parent 0d001bb982
commit c92c9b99b2
No known key found for this signature in database
GPG Key ID: 2F7B001CA27A8132
2 changed files with 35 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?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.
*
* @param array $options
* @return bool
*/
public function save(array $options = [])
{
$changes = $this->getDirty();
// Check for 2 changed values because one is always the updated_at column
if (!array_key_exists('last_used_at', $changes) || count($changes) > 2) {
parent::save();
}
return false;
}
}

View File

@ -2,6 +2,8 @@
namespace App\Providers;
use Laravel\Sanctum\Sanctum;
use App\Models\PersonalAccessToken;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\ServiceProvider;
@ -26,6 +28,8 @@ public function boot()
{
//
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
Http::macro('remote', function ($api_token, $url) {
// 关闭证书验证
return Http::withoutVerifying()->withHeaders([