refactor: kb & station & terminal
This commit is contained in:
48
app/Models/Station.php
Normal file
48
app/Models/Station.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user