Update
This commit is contained in:
@@ -42,6 +42,6 @@ class Order extends Model
|
||||
|
||||
public function getFormattedTotalAttribute(): string
|
||||
{
|
||||
return '€ ' . number_format($this->total, 2, ',', '.');
|
||||
return '€ '.number_format($this->total, 2, ',', '.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class Product extends Model
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'makerworld_id',
|
||||
'category_id',
|
||||
'name',
|
||||
'slug',
|
||||
@@ -27,12 +28,16 @@ class Product extends Model
|
||||
'weight_grams',
|
||||
'print_time_hours',
|
||||
'image_url',
|
||||
'makerworld_url',
|
||||
'makerworld_author',
|
||||
'makerworld_license',
|
||||
'gallery_images',
|
||||
'available_materials',
|
||||
'available_colors',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'makerworld_id' => 'integer',
|
||||
'base_price' => 'float',
|
||||
'is_print_on_demand' => 'boolean',
|
||||
'is_featured' => 'boolean',
|
||||
@@ -55,6 +60,6 @@ class Product extends Model
|
||||
|
||||
public function getFormattedPriceAttribute(): string
|
||||
{
|
||||
return '€ ' . number_format($this->base_price, 2, ',', '.');
|
||||
return '€ '.number_format($this->base_price, 2, ',', '.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $keyType = 'string';
|
||||
|
||||
protected $fillable = [
|
||||
'key',
|
||||
'value',
|
||||
];
|
||||
|
||||
public static function get(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$setting = static::query()->find($key);
|
||||
|
||||
if (! $setting || $setting->value === null) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
$decoded = json_decode($setting->value, true);
|
||||
|
||||
return (json_last_error() === JSON_ERROR_NONE) ? $decoded : $setting->value;
|
||||
}
|
||||
|
||||
public static function set(string $key, mixed $value): static
|
||||
{
|
||||
$encoded = is_array($value) || is_object($value) ? json_encode($value) : (string) $value;
|
||||
|
||||
return static::query()->updateOrCreate(
|
||||
['key' => $key],
|
||||
['value' => $encoded]
|
||||
);
|
||||
}
|
||||
|
||||
public static function forget(string $key): bool
|
||||
{
|
||||
return (bool) static::query()->where('key', $key)->delete();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user