38 lines
875 B
PHP
38 lines
875 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Document extends Model
|
|
{
|
|
protected $table = 'document';
|
|
|
|
use HasFactory;
|
|
|
|
const STATUS_NOT_APPLIED = 0;
|
|
const STATUS_APPLIED = 1;
|
|
const TYPE_TO = 0;
|
|
const TYPE_FROM = 1;
|
|
protected $fillable = ['type', 'date', 'status'];
|
|
|
|
public function products(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Product::class);
|
|
}
|
|
|
|
public static function getTitlesOfTypes()
|
|
{
|
|
return [self::TYPE_TO => 'Поступление', self::TYPE_FROM => 'Расход'];
|
|
}
|
|
|
|
public function documentProducts(): HasMany
|
|
{
|
|
return $this->hasMany(DocumentProduct::class);
|
|
}
|
|
|
|
}
|