Fix missing likes field

This commit is contained in:
Pig Fang 2019-03-15 13:14:59 +08:00
parent 3a147c8ec4
commit 13fade2773
2 changed files with 5 additions and 6 deletions

View File

@ -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([]);
}

View File

@ -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();