/var/www/html/back/app/Models/Article.php
<?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 string $name
* @property string $article_type
* @property int|null $article_group_id
* @property float $payment_limits
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
* @property-read ArticleGroup|null $group
* @property-read Collection|Project[] $projects
* @property Collection|PaymentDistribution[] $paymentDistributions
* @property-read Collection|ArticleToProject[] $articleProjectLinks
* @property bool $default_in_project
*/
class Article extends Model
{
protected $fillable = [
'name',
'model_id',
'article_type',
'article_group_id',
'payment_limits',
'sort',
'default_in_project',
];
public function group(): BelongsTo
{
return $this->belongsTo(ArticleGroup::class, 'article_group_id')->withDefault();
}
public function paymentDistributions(): HasMany
{
return $this->hasMany(PaymentDistribution::class);
}
public function articleProjectLinks(): HasMany
{
return $this->hasMany(ArticleToProject::class);
}
public function payments(): BelongsToMany
{
return $this->belongsToMany(Payment::class, 'payment_distributions');
}
public function projects(): BelongsToMany
{
return $this->belongsToMany(Project::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,
'name' => 'Example Article',
'article_type' => 'debit',
'article_group_id' => 1,
'group' => ArticleGroup::example(),
'created_at' => now(),
'updated_at' => now()
];
}
}