Archived
1
0
Fork 0

app/View/Components: minor fixes.

This commit is contained in:
Henrik Hautakoski 2021-07-20 15:21:40 +02:00
parent 766da19bb5
commit e4363c078a
4 changed files with 16 additions and 6 deletions

View file

@ -6,5 +6,5 @@ use Illuminate\View\Component;
class ClassIcon extends Icon
{
protected $prefix = 'classes';
protected string $prefix = 'classes';
}

View file

@ -8,9 +8,15 @@ use Illuminate\View\Component;
abstract class Icon extends Component
{
protected $prefix = '';
/**
* Path prefix.
*/
protected string $prefix = '';
public $url;
/**
* Image url.
*/
public string $url;
/**
* Create a new component instance.
@ -19,7 +25,11 @@ abstract class Icon extends Component
*/
public function __construct(string $name)
{
$file = sprintf('%s/%s.jpg', $this->prefix, Str::lower($name));
$file = Str::of($name)->lower()->append('.jpg');
if (strlen($this->prefix)) {
$file = collect([$this->prefix, $file])->join('/');
}
$this->url = Storage::disk('images')->url($file);
}

View file

@ -4,5 +4,5 @@ namespace App\View\Components;
class ProfessionIcon extends Icon
{
protected $prefix = 'professions';
protected string $prefix = 'professions';
}

View file

@ -7,7 +7,7 @@ use Illuminate\Support\Str;
class RaceIcon extends Icon
{
protected $prefix = 'races';
protected string $prefix = 'races';
/**
* Create a new component instance.