Casting json categories column to array, filtering by categories.
This commit is contained in:
@@ -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)),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user