diff --git a/app/Http/Controllers/SkinlibController.php b/app/Http/Controllers/SkinlibController.php index a3edd1ec..8756259d 100644 --- a/app/Http/Controllers/SkinlibController.php +++ b/app/Http/Controllers/SkinlibController.php @@ -151,7 +151,7 @@ class SkinlibController extends Controller public function info($tid) { if ($t = Texture::find($tid)) { - return json(array_merge($t->toArray(), ['likes' => $t->likes])); + return json($t->toArray()); } else { return json([]); } diff --git a/app/Models/Texture.php b/app/Models/Texture.php index 51f62f7c..bc80f298 100644 --- a/app/Models/Texture.php +++ b/app/Models/Texture.php @@ -9,11 +9,6 @@ class Texture extends Model public $primaryKey = 'tid'; public $timestamps = false; - /** - * The attributes that should be cast to native types. - * - * @var array - */ protected $casts = [ 'tid' => 'integer', 'size' => 'integer', @@ -21,6 +16,10 @@ class Texture extends Model 'public' => 'boolean', ]; + protected $appends = [ + 'likes' + ]; + public function getLikesAttribute() { return $this->likers()->count();