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