blessing-skin-server/app/Models/Texture.php

39 lines
770 B
PHP
Raw Normal View History

2016-07-21 22:01:57 +08:00
<?php
namespace App\Models;
2016-10-23 11:41:52 +08:00
use Illuminate\Database\Eloquent\Model;
class Texture extends Model
2016-07-21 22:01:57 +08:00
{
public $primaryKey = 'tid';
2019-03-16 16:32:49 +08:00
public const CREATED_AT = 'upload_at';
public const UPDATED_AT = null;
2016-07-21 22:01:57 +08:00
2018-02-23 09:51:23 +08:00
protected $casts = [
'tid' => 'integer',
'size' => 'integer',
'uploader' => 'integer',
2018-07-16 11:10:01 +08:00
'public' => 'boolean',
2018-02-23 09:51:23 +08:00
];
2019-03-15 13:14:59 +08:00
protected $appends = [
'likes',
2019-03-15 13:14:59 +08:00
];
2019-03-14 23:55:49 +08:00
public function getLikesAttribute()
{
return $this->likers()->count();
}
2016-07-21 22:01:57 +08:00
public function scopeLike($query, $field, $value)
{
return $query->where($field, 'LIKE', "%$value%");
}
2019-03-14 23:55:49 +08:00
public function likers()
{
return $this->belongsToMany(User::class, 'user_closet')->withPivot('item_name');
}
2016-07-21 22:01:57 +08:00
}