• File: Project.php
  • Full Path: /var/www/html/back/app/Models/Project.php
  • File size: 2.68 KB
  • MIME-type: text/x-php
  • Charset: utf-8
<?php

declare(strict_types=1);

namespace App\Models;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;

/**
 * @property int $id
 * @property int $model_id
 * @property float $project_limits
 * @property string $status
 * @property string $offer_number
 * @property string $object_address
 * @property string $short_description
 * @property string|null $description
 * @property int|null $project_group_id
 * @property Carbon $created_at
 * @property Carbon $updated_at
 * @property Collection|PaymentDistribution[] $paymentDistributions
 * @property-read Collection|Article[] $articles
 * @property-read Collection|ArticleToProject[] $articleProjectLinks
 * @property ProjectGroup|null $projectGroup
 */
class Project extends Model
{
    protected $table = 'projects';

    protected $fillable = [
        'model_id',
        'project_limits',
        'status',
        'offer_number',
        'object_address',
        'short_description',
        'description',
        'project_group_id',
        'project_limits_credit',
        'project_limits_debit',
    ];

    public function paymentDistributions(): HasMany
    {
        return $this->hasMany(PaymentDistribution::class);
    }

    protected $casts = [
        'project_limits' => 'decimal:2',
    ];

    /**
     * Связь с группой проектов.
     *
     * @return BelongsTo
     */
    public function projectGroup(): BelongsTo
    {
        return $this->belongsTo(ProjectGroup::class, 'project_group_id');
    }

    public function articleProjectLinks(): HasMany
    {
        return $this->hasMany(ArticleToProject::class);
    }

    public function articles(): BelongsToMany
    {
        return $this->belongsToMany(Article::class, 'article_to_project')
            ->withPivot('amount_limit')
            ->withTimestamps();
    }

    public function model(): BelongsTo
    {
        return $this->belongsTo(System::class);
    }

    public static function example(): array
    {
        return [
            'id' => 1,
            'model_id' => 1,
            'project_limits' => 10000000.00,
            'status' => 'active',
            'offer_number' => '123456789',
            'object_address' => '123 Main St',
            'short_description' => 'Example Project',
            'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
            'project_group_id' => 1,
            'created_at' => now(),
            'updated_at' => now(),
            'projectGroup' => []
        ];
    }
}