Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mprythero's avatar

Workflows and Rule Requirements

Has anyone had the opportunity to deal with rules such as having a specific relationship or having a field with a specific value and workflow? I am trying to find how to best design my workflow portion of my application but I am getting stuck on a few things that are leading me to a brick wall.

What I am trying to accomplish is if a workflow step can be completed by first checking the rules above. These workflow steps could be applied to any other model in my application, not just one and there can be an infinite number of workflow steps. But I'm stuck on how to execute this idea and whether or not anyone has come across workflows and rules like mine.

Thanks

0 likes
4 replies
webrobert's avatar

@mprythero Not completely following what you’re imagining but sometimes you just have to start writing some code. Or at least the steps. Do you have something to share here?

mprythero's avatar

@martinbean - I will look into it and see if and how I can best utilize it, I do appreciate the suggestion!

As for @webrobert - Some of my test code is below, I honestly don't know where I am going with it at this point...

public function canComplete(){
    $parent = $this->workflowable()->first();

    if($this->wf_template_id == 3 || $this->wf_template_id == 1){
        if(!$parent->address_id){ // Field of parent must be filled
            return ['response'=>false, 'message'=>'Address must be standardized prior to completion'];
        }else{
            return ['response'=>true];
        }
    }else if($this->wf_template_id == 2){
        if(!$parent->attachments()->where('type_id', 8)){
            return ['response'=>false, 'message'=>'Attachments must have scanned image of completed transfer documentation'];
        }else{
            return ['response'=>true];
        }
    }
}

I am not sure how best to set individual rules for each workflow step, or how to best complete the responses along with trues or falses.

I'd appreciate any suggestions you might have. Like I said, at this point I am just trying to test waters because I don't quite know where I am going with this.

Thanks!

scotty2hotty's avatar

you ever found a cleaner way to handle rule conditions that depend on workflow stages?? I'm currently trying to keep my validation logic clean while adapting to changes in the business flow, and it’s starting to feel like my form requests are getting messy. Curious how others are approaching this now.

Please or to participate in this conversation.