Initial commit
This commit is contained in:
37
app/Models/IssueLabel.php
Normal file
37
app/Models/IssueLabel.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class IssueLabel extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'color',
|
||||
'description',
|
||||
];
|
||||
|
||||
public function issues(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Issue::class, 'issue_label_pivot');
|
||||
}
|
||||
|
||||
public function getTextColorAttribute(): string
|
||||
{
|
||||
// Calculate if we should use black or white text based on background color
|
||||
$color = $this->color;
|
||||
$r = hexdec(substr($color, 1, 2));
|
||||
$g = hexdec(substr($color, 3, 2));
|
||||
$b = hexdec(substr($color, 5, 2));
|
||||
|
||||
// Calculate perceived brightness
|
||||
$brightness = (($r * 299) + ($g * 587) + ($b * 114)) / 1000;
|
||||
|
||||
return $brightness > 128 ? '#000000' : '#FFFFFF';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user