sarga/packages/Webkul/Core/src/Models/Locale.php

94 lines
2.0 KiB
PHP
Raw Normal View History

2018-07-11 05:41:27 +00:00
<?php
namespace Webkul\Core\Models;
2021-12-22 13:40:40 +00:00
use Illuminate\Database\Eloquent\Factories\Factory;
2021-12-29 13:59:19 +00:00
use Illuminate\Database\Eloquent\Factories\HasFactory;
2018-07-11 05:41:27 +00:00
use Illuminate\Database\Eloquent\Model;
2021-12-29 13:59:19 +00:00
use Illuminate\Support\Facades\Storage;
2019-02-18 07:30:40 +00:00
use Webkul\Core\Contracts\Locale as LocaleContract;
2021-12-29 13:59:19 +00:00
use Webkul\Core\Database\Factories\LocaleFactory;
2018-07-11 05:41:27 +00:00
2019-02-18 07:30:40 +00:00
class Locale extends Model implements LocaleContract
2018-07-11 05:41:27 +00:00
{
use HasFactory;
2021-12-30 11:24:12 +00:00
/**
* List of all default locale images for velocity.
*
* @var array
*/
protected $defaultImage = [
'de' => 'flags/de.png',
'en' => 'flags/en.png',
'es' => 'flags/es.png',
'fr' => 'flags/fr.png',
'nl' => 'flags/nl.png',
'tr' => 'flags/tr.png',
];
2018-07-11 05:41:27 +00:00
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
2020-02-27 08:03:03 +00:00
'code',
'name',
'direction',
2018-07-11 05:41:27 +00:00
];
2021-12-29 13:59:19 +00:00
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = ['image_url'];
/**
* Create a new factory instance for the model.
*
2021-12-22 13:40:40 +00:00
* @return Factory
*/
2021-12-22 13:40:40 +00:00
protected static function newFactory(): Factory
{
2021-12-29 13:59:19 +00:00
return LocaleFactory::new ();
}
/**
* Get image url for the logo image.
*
* @return string
*/
2021-12-30 11:24:12 +00:00
public function getImageUrlAttribute(): string
2021-12-29 13:59:19 +00:00
{
2021-12-30 11:24:12 +00:00
return $this->image_url();
}
2021-12-30 07:54:10 +00:00
2021-12-30 11:24:12 +00:00
/**
* Get image url for the logo image.
*
* @return string
*/
public function image_url(): string
{
if (! $this->locale_image) {
return $this->getDefaultImageSource();
2021-12-29 13:59:19 +00:00
}
return Storage::url($this->locale_image);
}
/**
2021-12-30 11:24:12 +00:00
* Get default image source.
2021-12-29 13:59:19 +00:00
*
* @return string
*/
2021-12-30 11:24:12 +00:00
public function getDefaultImageSource(): string
2021-12-29 13:59:19 +00:00
{
2021-12-30 11:24:12 +00:00
return isset($this->defaultImage[$this->code]) && file_exists($this->defaultImage[$this->code])
? asset($this->defaultImage[$this->code])
: '';
}
}