restore composer.json, add mysqli extension
This commit is contained in:
49
app/Models/Region.php
Executable file
49
app/Models/Region.php
Executable file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Traits\LogOptionsTrait;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
class Region extends Model
|
||||
{
|
||||
use LogsActivity, LogOptionsTrait;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $casts = [
|
||||
'name' => 'array',
|
||||
'cash' => 'boolean'
|
||||
];
|
||||
|
||||
protected static $logName = 'regions';
|
||||
protected static $logOnlyDirty = true;
|
||||
protected static $logAttributes = ['name', 'cash'];
|
||||
protected static $submitEmptyLogs = false;
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function cities()
|
||||
{
|
||||
return $this->hasMany(City::class, 'region_id', 'id');
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return (string) $this->name[App::getLocale()] ?? null;
|
||||
}
|
||||
|
||||
public function deliveryPrice()
|
||||
{
|
||||
return $this->hasMany(DeliveryPrice::class, 'region_id', 'id');
|
||||
}
|
||||
|
||||
public function getDeliveryPrice($powerId): ?float
|
||||
{
|
||||
$deliveryPrice = collect($this->deliveryPrice)->where('power_id', $powerId)->first();
|
||||
return $deliveryPrice ? $deliveryPrice['price'] : null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user