Lae/app/Models/Server/Status.php

39 lines
753 B
PHP
Raw Normal View History

2022-08-13 10:23:34 +00:00
<?php
namespace App\Models\Server;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Status extends Model
{
use HasFactory;
protected $table = 'server_status';
protected $fillable = [
'name',
'ip',
'status',
2022-08-14 13:57:56 +00:00
'module_id',
2022-08-13 10:23:34 +00:00
];
// scope
2022-08-14 13:57:56 +00:00
public function scopeModule($query)
2022-08-13 10:23:34 +00:00
{
2022-08-14 13:57:56 +00:00
return $query->where('module_id', auth('remote')->id());
}
// when update, check owner
protected static function boot()
{
parent::boot();
static::updating(function ($model) {
if ($model->module_id !== auth('remote')->id()) {
abort(403, 'Unauthorized action.');
}
});
2022-08-13 10:23:34 +00:00
}
}