mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-07 00:42:34 +00:00
2.x
This commit is contained in:
22
app/Traits/HasProjectThroughServer.php
Normal file
22
app/Traits/HasProjectThroughServer.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
|
||||
trait HasProjectThroughServer
|
||||
{
|
||||
public function project(): HasOneThrough
|
||||
{
|
||||
return $this->hasOneThrough(
|
||||
Project::class,
|
||||
Server::class,
|
||||
'id',
|
||||
'id',
|
||||
'server_id',
|
||||
'project_id'
|
||||
);
|
||||
}
|
||||
}
|
35
app/Traits/HasTimezoneTimestamps.php
Normal file
35
app/Traits/HasTimezoneTimestamps.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* @property string $created_at_by_timezone
|
||||
* @property string $updated_at_by_timezone
|
||||
*/
|
||||
trait HasTimezoneTimestamps
|
||||
{
|
||||
public function getCreatedAtByTimezoneAttribute(): string
|
||||
{
|
||||
return $this->getDateTimeByTimezone($this->created_at);
|
||||
}
|
||||
|
||||
public function getUpdatedAtByTimezoneAttribute(): string
|
||||
{
|
||||
return $this->getDateTimeByTimezone($this->updated_at);
|
||||
}
|
||||
|
||||
public function getDateTimeByTimezone(?Carbon $value = null): ?string
|
||||
{
|
||||
if ($value && auth()->user() && auth()->user()->timezone) {
|
||||
try {
|
||||
return date_with_timezone($value, auth()->user()->timezone);
|
||||
} catch (Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user