Inventory.php 794 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelTimeFormat;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. class Inventory extends Model
  7. {
  8. use ModelTimeFormat;
  9. use SoftDeletes;
  10. protected $fillable=[
  11. 'id','owner_id','owner_id','type', 'start_at', 'end_at','total','processed','difference','returned','deleted_at','created_at',
  12. ];
  13. protected $appends = [
  14. 'surplus'
  15. ];
  16. public function owner(){
  17. return $this->belongsTo('App\Owner','owner_id','id');
  18. }
  19. public function inventoryMissions(){
  20. return $this->belongsTo('App\InventoryMission','id','inventory_id');
  21. }
  22. public function getSurplusAttribute()
  23. {
  24. return $this['total'] ? $this['total']-$this['processed']:null;
  25. }
  26. }