Skip to content

Commit

Permalink
#405 - removing rackbeat/laravel-ui-avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztofrewak committed Mar 27, 2024
1 parent 72fb588 commit bfbcde3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 479 deletions.
42 changes: 42 additions & 0 deletions app/Domain/UiAvatar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace Toby\Domain;

use Stringable;

class UiAvatar implements Stringable
{
public int $length = 2;
public float $fontSize = 0.33;
public int $size = 128;
public bool $rounded = true;
public bool $uppercase = true;
public string $background = "#A0A0A0";
public string $color = "#FFFFFF";
public bool $bold = true;
public string $region = "eu";
public string $name = "";

public function __toString(): string
{
return $this->getUrl();
}

public function getUrl(): string
{
return "https://eu.ui-avatars.com/api/?" . http_build_query([
"length" => $this->length,
"font-size" => $this->fontSize,
"size" => $this->size,
"rounded" => $this->rounded ? 1 : 0,
"uppercase" => $this->uppercase ? 1 : 0,
"background" => $this->background,
"color" => $this->color,
"bold" => $this->bold ? 1 : 0,
"region" => $this->region,
"name" => $this->name,
]);
}
}
16 changes: 6 additions & 10 deletions app/Models/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Carbon;
use Rackbeat\UIAvatars\HasAvatar;
use Toby\Domain\UiAvatar;
use Toby\Enums\EmploymentForm;
use Toby\Helpers\ColorGenerator;

Expand All @@ -29,7 +29,6 @@
class Profile extends Model
{
use HasFactory;
use HasAvatar;

protected $primaryKey = "user_id";
protected $guarded = [];
Expand All @@ -51,21 +50,18 @@ public function user(): BelongsTo

public function getAvatar(): string
{
return $this->getAvatarGenerator()
->backgroundColor(ColorGenerator::generate($this->full_name))
->image();
$avatar = new UiAvatar();
$avatar->background = ColorGenerator::generate($this->full_name);
$avatar->name = mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);

return $avatar->getUrl();
}

public function getFullNameAttribute(): string
{
return "{$this->first_name} {$this->last_name}";
}

protected function getAvatarName(): string
{
return mb_substr($this->first_name, 0, 1) . mb_substr($this->last_name, 0, 1);
}

protected static function newFactory(): ProfileFactory
{
return ProfileFactory::new();
Expand Down
7 changes: 0 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
"description": "HR software you love to hate",
"keywords": ["toby", "laravel", "hr"],
"license": "MIT",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/laravel-shift/laravel-ui-avatars.git"
}
],
"require": {
"php": "^8.3",
"ext-pdo": "*",
Expand All @@ -27,7 +21,6 @@
"laravel/tinker": "^2.9",
"maatwebsite/excel": "^3.1",
"phpoffice/phpword": "1.1",
"rackbeat/laravel-ui-avatars": "dev-l11-compatibility",
"sentry/sentry-laravel": "^4.2",
"spatie/laravel-google-calendar": "3.8",
"spatie/laravel-model-states": "^2.6",
Expand Down
Loading

0 comments on commit bfbcde3

Please sign in to comment.