refactor: kb & station & terminal

This commit is contained in:
2026-03-23 20:17:17 +08:00
parent 63ea2686e1
commit b74ba1a3f8
81 changed files with 1016 additions and 2492 deletions

48
app/Models/Station.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Station extends Model
{
use HasFactory;
protected $fillable = [
'name',
'description',
];
protected static function boot()
{
parent::boot();
static::deleting(function (Station $station) {
$station->terminals()->update(['station_id' => null]);
});
}
public function terminals(): HasMany
{
return $this->hasMany(Terminal::class);
}
public function knowledgeBases(): BelongsToMany
{
return $this->belongsToMany(KnowledgeBase::class);
}
public function users(): BelongsToMany
{
return $this->belongsToMany(User::class);
}
public function guides(): BelongsToMany
{
return $this->belongsToMany(Guide::class);
}
}