| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- declare(strict_types=1);
- namespace App\Models;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\Relations\HasOne;
- class DocumentationDocument extends Model
- {
- use HasFactory;
- protected $fillable = [
- 'folder_id',
- 'name',
- 'last_version_number',
- 'created_by',
- ];
- protected function casts(): array
- {
- return [
- 'last_version_number' => 'integer',
- ];
- }
- public function folder(): BelongsTo
- {
- return $this->belongsTo(DocumentationFolder::class, 'folder_id');
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class, 'created_by');
- }
- public function versions(): HasMany
- {
- return $this->hasMany(DocumentationDocumentVersion::class, 'document_id')
- ->orderByDesc('version');
- }
- public function currentVersion(): HasOne
- {
- return $this->hasOne(DocumentationDocumentVersion::class, 'document_id')
- ->ofMany('version', 'max');
- }
- }
|