1
0
mirror of https://github.com/cp6/my-idlers.git synced 2024-11-16 23:42:32 +01:00
my-idlers/app/Models/Labels.php

56 lines
1.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Cache;
class Labels extends Model
{
use HasFactory;
public $incrementing = false;
protected $table = 'labels';
2022-07-22 15:49:18 +02:00
protected $keyType = 'string';
protected $fillable = ['id', 'label', 'server_id', 'server_id_2', 'domain_id', 'domain_id_2', 'shared_id', 'shared_id_2'];
2023-08-19 15:46:18 +02:00
public static function deleteLabelsAssignedTo($service_id): void
{
LabelsAssigned::where('service_id', $service_id)->delete();
}
2023-08-19 15:46:18 +02:00
public static function deleteLabelAssignedAs($label_id): void
{
LabelsAssigned::where('label_id', $label_id)->delete();
}
2023-08-19 15:46:18 +02:00
public static function insertLabelsAssigned(array $labels_array, string $service_id): void
{
for ($i = 1; $i <= 4; $i++) {
if (!is_null($labels_array[($i - 1)])) {
2023-08-19 15:58:25 +02:00
LabelsAssigned::create([
'label_id' => $labels_array[($i - 1)],
'service_id' => $service_id
]);
}
}
}
2023-08-19 15:46:18 +02:00
public static function labelsCount(): int
{
return Cache::remember('labels_count', now()->addMonth(1), function () {
2023-08-18 11:28:53 +02:00
return Labels::count();
});
}
2023-08-19 15:46:18 +02:00
public function assigned(): \Illuminate\Database\Eloquent\Relations\HasMany
{
return $this->hasMany(LabelsAssigned::class, 'label_id', 'id');
}
}