mirror of https://github.com/movim/movim
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
883 B
36 lines
883 B
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Hat extends Model
|
|
{
|
|
protected $fillable = ['uri', 'title', 'hue', 'presence_id'];
|
|
|
|
public function presence()
|
|
{
|
|
return $this->belongsTo(Presence::class);
|
|
}
|
|
|
|
public function toArray()
|
|
{
|
|
$now = \Carbon\Carbon::now();
|
|
|
|
return [
|
|
'uri' => $this->attributes['uri'],
|
|
'title' => $this->attributes['title'],
|
|
'hue' => $this->attributes['hue'] ?? null,
|
|
'presence_id' => $this->attributes['presence_id'],
|
|
'created_at' => $this->attributes['created_at'] ?? $now,
|
|
'updated_at' => $this->attributes['updated_at'] ?? $now,
|
|
];
|
|
}
|
|
|
|
public function getColorAttribute(): string
|
|
{
|
|
return $this->hue
|
|
? hueToPalette($this->hue)
|
|
: stringToColor($this->uri);
|
|
}
|
|
}
|