generated from liutk/owl-admin-base
41 lines
773 B
PHP
41 lines
773 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use EloquentFilter\Filterable;
|
|
|
|
class ActivityGame extends Model
|
|
{
|
|
use HasFactory,Filterable;
|
|
|
|
protected $casts = [
|
|
'game_at' => 'datetime:Y-m-d H:i:s'
|
|
];
|
|
|
|
protected $fillable = [
|
|
'state', 'score',
|
|
];
|
|
|
|
public function scopeShow($q)
|
|
{
|
|
$q->where('state', '>' ,0);
|
|
}
|
|
|
|
public function scopeSort($q)
|
|
{
|
|
$q->orderBy('game_at', 'desc')->orderBy('created_at', 'desc');
|
|
}
|
|
|
|
public function logs()
|
|
{
|
|
return $this->hasMany(UserGame::class, 'game_id');
|
|
}
|
|
|
|
public function activity()
|
|
{
|
|
return $this->belongsTo(Activity::class, 'activity_id');
|
|
}
|
|
}
|