You've already forked Atomcms-edit
Initial commit
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Staff;
|
||||
|
||||
use App\Models\Community\Teams\WebsiteTeam;
|
||||
use App\Models\Game\Permission;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteOpenPosition canApply()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteOpenPosition get($columns = ['*'])
|
||||
*/
|
||||
class WebsiteOpenPosition extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'website_open_positions';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'rank_id'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'apply_from' => 'datetime',
|
||||
'apply_to' => 'datetime',
|
||||
];
|
||||
|
||||
#[\Override]
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function ($openPosition) {
|
||||
if ($openPosition->position_kind === 'rank' && $openPosition->permission_id) {
|
||||
WebsiteStaffApplications::where('rank_id', $openPosition->permission_id)->delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function permission()
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'permission_id', 'id');
|
||||
}
|
||||
|
||||
public function team()
|
||||
{
|
||||
return $this->belongsTo(WebsiteTeam::class, 'team_id', 'id');
|
||||
}
|
||||
|
||||
public function applications()
|
||||
{
|
||||
return $this->hasMany(WebsiteStaffApplications::class, 'rank_id', 'permission_id');
|
||||
}
|
||||
|
||||
public function scopeCanApply($query)
|
||||
{
|
||||
return $query->where('apply_from', '<=', now())->where('apply_to', '>', now());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user