39 lines
770 B
PHP
39 lines
770 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Texture extends Model
|
|
{
|
|
public $primaryKey = 'tid';
|
|
public const CREATED_AT = 'upload_at';
|
|
public const UPDATED_AT = null;
|
|
|
|
protected $casts = [
|
|
'tid' => 'integer',
|
|
'size' => 'integer',
|
|
'uploader' => 'integer',
|
|
'public' => 'boolean',
|
|
];
|
|
|
|
protected $appends = [
|
|
'likes',
|
|
];
|
|
|
|
public function getLikesAttribute()
|
|
{
|
|
return $this->likers()->count();
|
|
}
|
|
|
|
public function scopeLike($query, $field, $value)
|
|
{
|
|
return $query->where($field, 'LIKE', "%$value%");
|
|
}
|
|
|
|
public function likers()
|
|
{
|
|
return $this->belongsToMany(User::class, 'user_closet')->withPivot('item_name');
|
|
}
|
|
}
|