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

68 lines
1.6 KiB
PHP
Raw Normal View History

2016-07-21 22:01:57 +08:00
<?php
namespace App\Models;
2020-03-09 12:29:00 +08:00
use DateTimeInterface;
2020-04-19 19:36:39 +08:00
use Illuminate\Database\Eloquent\Collection;
2016-10-23 11:41:52 +08:00
use Illuminate\Database\Eloquent\Model;
2020-04-19 19:36:39 +08:00
use Illuminate\Support\Carbon;
2016-10-23 11:41:52 +08:00
2020-04-19 19:36:39 +08:00
/**
* @property int $tid
* @property string $name
* @property string $type
* @property string $hash
* @property int $size
* @property int $uploader
* @property bool $public
* @property Carbon $upload_at
* @property int $likes
* @property string $model
* @property User $owner
* @property Collection $likers
*/
2016-10-23 11:41:52 +08:00
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',
'likes' => 'integer',
2018-02-23 09:51:23 +08:00
];
2019-05-07 15:16:53 +08:00
protected $dispatchesEvents = [
'deleting' => \App\Events\TextureDeleting::class,
];
2019-12-30 23:29:44 +08:00
public function getModelAttribute()
{
// Don't worry about cape...
return $this->type === 'alex' ? 'slim' : 'default';
}
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
2020-03-24 18:05:46 +08:00
public function owner()
{
return $this->belongsTo(User::class, 'uploader');
}
2019-03-14 23:55:49 +08:00
public function likers()
{
return $this->belongsToMany(User::class, 'user_closet')->withPivot('item_name');
}
2020-03-09 12:29:00 +08:00
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
2016-07-21 22:01:57 +08:00
}