Record.php 908 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class Record extends Model
  6. {
  7. use HasFactory;
  8. protected $fillable = [
  9. 'member_id',
  10. 'supplier_id',
  11. // 'causal_id',
  12. 'payment_method_id',
  13. 'date',
  14. //'month',
  15. //'year',
  16. 'type',
  17. //'amount',
  18. //'note',
  19. //'commercial',
  20. ];
  21. public function member()
  22. {
  23. return $this->belongsTo(Member::class);
  24. }
  25. public function supplier()
  26. {
  27. return $this->belongsTo(Supplier::class);
  28. }
  29. public function payment_method()
  30. {
  31. return $this->belongsTo(PaymentMethod::class);
  32. }
  33. public function rows()
  34. {
  35. return $this->hasMany(RecordRow::class);
  36. }
  37. public function getTotal()
  38. {
  39. return $this->rows->sum('amount');
  40. }
  41. }