init
This commit is contained in:
commit
0f260ab95f
|
|
@ -0,0 +1,2 @@
|
|||
docker
|
||||
.vscode
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
/.vscode export-ignore
|
||||
/.gitattributes export-ignore
|
||||
/.gitignore export-ignore
|
||||
/phpunit.xml.dist export-ignore
|
||||
/docs export-ignore
|
||||
/tests export-ignore
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
reports
|
||||
sandbox
|
||||
vendor
|
||||
composer.lock
|
||||
.idea/
|
||||
workbench
|
||||
.phpunit.result.cache
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"editor.formatOnSave": true,
|
||||
"[php]": {
|
||||
"editor.defaultFormatter": "bmewburn.vscode-intelephense-client"
|
||||
},
|
||||
}
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
"name": "blax-software/laravel-workkit",
|
||||
"type": "library",
|
||||
"description": "Laravel collection of helpers and utilities to speed up development.",
|
||||
"keywords": [],
|
||||
"homepage": "http://www.blax.at",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabian Wagner",
|
||||
"email": "fabian@blax.at",
|
||||
"homepage": "https://www.blax.at",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Blax\\Workkit\\": "src"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.0",
|
||||
"laravel/framework": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"laravel/pint": "^1.22"
|
||||
},
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": []
|
||||
}
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"autoload-dev": {
|
||||
"psr-4": {}
|
||||
},
|
||||
"scripts": {
|
||||
"post-autoload-dump": [
|
||||
"@clear",
|
||||
"@prepare"
|
||||
],
|
||||
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
|
||||
"prepare": "@php vendor/bin/testbench package:discover --ansi",
|
||||
"build": "@php vendor/bin/testbench workbench:build --ansi",
|
||||
"serve": [
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"@build",
|
||||
"@php vendor/bin/testbench serve --ansi"
|
||||
],
|
||||
"lint": [
|
||||
"@php vendor/bin/pint --ansi"
|
||||
],
|
||||
"test": [
|
||||
"@clear",
|
||||
"@php vendor/bin/phpunit"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Blax\Workkit\Traits;
|
||||
|
||||
trait HasExpiration
|
||||
{
|
||||
public static function bootWillExpire()
|
||||
{
|
||||
static::addGlobalScope('willExpire', function ($builder) {
|
||||
$builder->where(function ($query) {
|
||||
$query->whereNull('expires_at')
|
||||
->orWhere('expires_at', '>', now());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public function isExpired(): bool
|
||||
{
|
||||
return $this->expires_at && $this->expires_at->isPast();
|
||||
}
|
||||
|
||||
public function extendByHours(int $hours, bool $expire_if_null = false): void
|
||||
{
|
||||
if ($this->expires_at === null && !$expire_if_null) {
|
||||
// Do not add expiration if it does not expire
|
||||
return;
|
||||
} elseif ($this->expires_at->isPast()) {
|
||||
$this->expires_at = now()->addHours($hours);
|
||||
} else {
|
||||
$this->expires_at = $this->expires_at->addHours($hours);
|
||||
}
|
||||
|
||||
$this->save();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue