Files
getgreen-backend/app/Models/Service.php
2026-04-28 15:02:06 +05:00

75 lines
1.5 KiB
PHP
Executable File

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Date;
use Illuminate\Support\Facades\Storage;
/**
* @package App\Models
* @property int $id
* @property array $name
* @property string $image
* @property string $status
* @property string $type
* @property int $position
* @property bool $is_power
* @property bool $with_problem
*
* @method getImage(): string
* @method getName(): string
*
* @property Status $getStatus
*/
class Service extends Model
{
use HasFactory;
protected $fillable = [
'name',
'image',
'status',
'type',
'is_power',
'position',
'with_problem'
];
protected $casts = [
'name' => 'array',
'is_power' => 'boolean',
'with_problem' => 'boolean'
];
public function getStatus()
{
return $this->belongsTo(Status::class, 'status', 'slug');
}
public function getName(): string
{
if (App::isLocale('ru')) {
return (string) $this->name['ru'];
}
return (string) $this->name['uz'];
}
public function getImage(): string
{
if (!empty($this->image)) {
return Storage::url($this->image);
}
return (string) 'images/no_brend.png';
}
public function problems()
{
return $this->belongsToMany(Problem::class, 'service_problems');
}
}