Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Azuriom/Azuriom

703 stars
2 code files
View Azuriom/Azuriom on GitHub

app/Casts/Color.php

Open in GitHub
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;
 
class Color implements CastsAttributes
{
public function get(Model $model, string $key, mixed $value, array $attributes): string
{
return '#'.$value;
}
 
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
{
$color = ltrim($value, '#');
 
// Convert short hex colors
if (strlen($color) === 3) {
return $color[0].$color[0].$color[1].$color[1].$color[2].$color[2];
}
 
return $color;
}
}

app/Models/Role.php

Open in GitHub
use Azuriom\Casts\Color;
 
class Role extends Model
{
// ...
 
protected $casts = [
'color' => Color::class,
'is_admin' => 'boolean',
];
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.