Laravel 11 + Livewire 3/Volt + Alpine.js + Tailwind app for household budget planning, transaction tracking, and financial dashboards. - Multi-tenant households with member invites - Plan: monthly/yearly budget per category with overrides - Suivi: transaction log with running balance (desktop + mobile quick-entry) - Dashboard: budget vs tracked breakdown + Chart.js donuts - Flux: Sankey diagram of income allocation - WCAG 2.1 AA color tokens, dark mode, accessible tables/forms - 50 Pest tests Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
47 lines
1018 B
PHP
47 lines
1018 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class BudgetLine extends Model
|
|
{
|
|
protected $fillable = ['household_id', 'category_id', 'year', 'month', 'amount'];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'amount' => 'decimal:2',
|
|
];
|
|
}
|
|
|
|
public function household(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Household::class);
|
|
}
|
|
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Category::class);
|
|
}
|
|
|
|
public function scopeForYear(Builder $query, int $year): Builder
|
|
{
|
|
return $query->where('year', $year);
|
|
}
|
|
|
|
public function scopeDefaultLine(Builder $query): Builder
|
|
{
|
|
return $query->whereNull('month');
|
|
}
|
|
|
|
public function scopeForMonth(Builder $query, int $month): Builder
|
|
{
|
|
return $query->where('month', $month);
|
|
}
|
|
}
|