改进 模型
This commit is contained in:
parent
0d001bb982
commit
c92c9b99b2
31
app/Models/PersonalAccessToken.php
Normal file
31
app/Models/PersonalAccessToken.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use Laravel\Sanctum\Sanctum;
|
||||||
|
use App\Models\PersonalAccessToken;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
@ -26,6 +28,8 @@ public function boot()
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
|
||||||
|
Sanctum::usePersonalAccessTokenModel(PersonalAccessToken::class);
|
||||||
|
|
||||||
Http::macro('remote', function ($api_token, $url) {
|
Http::macro('remote', function ($api_token, $url) {
|
||||||
// 关闭证书验证
|
// 关闭证书验证
|
||||||
return Http::withoutVerifying()->withHeaders([
|
return Http::withoutVerifying()->withHeaders([
|
||||||
|
Loading…
Reference in New Issue
Block a user