From 0a10264850a12bfc11e2a1a1da2047e15c04200e Mon Sep 17 00:00:00 2001 From: alex-chevski Date: Wed, 6 Dec 2023 13:43:55 +0300 Subject: [PATCH] added casts to plan model --- app/Models/Plan.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Models/Plan.php b/app/Models/Plan.php index 6f81b28..708d131 100644 --- a/app/Models/Plan.php +++ b/app/Models/Plan.php @@ -12,13 +12,22 @@ use CyrildeWit\EloquentViewable\Contracts\Viewable; class Plan extends Model implements Viewable { - use HasFactory, InteractsWithViews; + use HasFactory; + use InteractsWithViews; protected $withCount = [ 'likes', 'comments' ]; + protected $casts = [ + 'type' => 'array', + 'packet1_options' => 'array', + 'packet2_options' => 'array', + 'packet3_options' => 'array', + ]; + + public function author() { return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id'); @@ -62,7 +71,7 @@ class Plan extends Model implements Viewable $data = $this->unserializeOptionsArr($this->type); return new Attribute( - get: fn() => array_keys($data), + get: fn () => array_keys($data), ); } @@ -79,7 +88,7 @@ class Plan extends Model implements Viewable } return new Attribute( - get: fn() => $result, + get: fn () => $result, ); }