ApprovalFlow.php 1006 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Models;
  3. use App\Http\Requests\IndexHelper;
  4. use App\Models\Enums\DisplayIndexObjectType;
  5. use App\Models\Scopes\CompanyScope;
  6. use Illuminate\Database\Eloquent\Factories\HasFactory;
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Database\Eloquent\SoftDeletes;
  9. class ApprovalFlow extends Model
  10. {
  11. use HasFactory, SoftDeletes;
  12. protected $fillable = [
  13. 'name', 'object_type', 'object_id', 'nodes', 'nodes_config', 'created_by',
  14. ];
  15. protected $casts = [
  16. 'nodes' => 'array',
  17. ];
  18. protected static function booted(): void
  19. {
  20. static::addGlobalScope(new CompanyScope);
  21. static::creating(function (ApprovalFlow $approvalFlow){
  22. $type =DisplayIndexObjectType::APPROVALFLOW;
  23. $displayIndex = IndexHelper::getObjectMaxIndex($type);
  24. $approvalFlow->display_id =$displayIndex;
  25. });
  26. }
  27. public function createdBy()
  28. {
  29. return $this->belongsTo(User::class, "created_by");
  30. }
  31. }