Casting json categories column to array, filtering by categories.

This commit is contained in:
Krzysztof Płaczek
2024-03-27 10:56:30 +01:00
parent b4536e4c6b
commit 3d49eb5c92
2 changed files with 50 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
namespace Krzysiej\RyobiCrawler\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
@@ -22,8 +23,17 @@ class Product extends Model
{
public $timestamps = true;
public $fillable = ['skuID'];
public function price(): HasMany
{
return $this->hasMany(Price::class);
}
protected function categories(): Attribute
{
return Attribute::make(
get: fn(string $value) => array_reverse(json_decode($value, 1)),
);
}
}