Files
project/app/Models/Payment.php

61 lines
1.2 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Date;
class Payment extends Model
{
public $timestamps = false;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'invoice_id',
'paid_amount',
'status',
'payment_method',
'payment_date',
];
/**
* The attributes that are appended with attribute getters.
*
* @var string[]
*/
protected $appends = [
'date',
'localized_state'
];
/**
* Get the payment state as translated string.
*/
public function getLocalizedStateAttribute(): string
{
return __('invoice.Payment state ' . $this->status);
}
/**
* Get the payment date as localized string.
*/
public function getDateAttribute(): string
{
return Date::createFromFormat('Y-m-d', $this->payment_date)->format('d.m.Y');
}
/**
* Get the invoice the payment belongs to.
*/
public function invoice(): BelongsTo
{
return $this->belongsTo(Invoice::class)->with(['customer']);
}
}