1. Go to this page and download the library: Download mrnewport/laravel-flow library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$entity = new SomeModel(...);
$flowInstance = FlowManager::startFlow('start_request',$entity);
// This creates a FlowInstance row + FlowInstanceStep row
// If step "start_request" has single_user with user_id=3, it is assigned to user 3.
namespace App\FlowAssignments;
use MrNewport\LaravelFlow\Models\FlowInstanceStep;
use MrNewport\LaravelFlow\Models\FlowStepAssignee;
use MrNewport\LaravelFlow\Assignments\AssignmentStrategyInterface;
class SlackChannelStrategy implements AssignmentStrategyInterface
{
public function __construct(protected array $params=[])
{
// e.g. $params['channel'] => '#general'
}
public function assign(FlowInstanceStep $instanceStep): void
{
// store the Slack channel
FlowStepAssignee::create([
'flow_instance_step_id'=>$instanceStep->id,
'assignee_type'=>'slack_channel',
'assignee_value'=>$this->params['channel']
]);
}
public function canReassign(FlowInstanceStep $instanceStep, $currentUser): bool
{
// If you have logic for reassigning Slack channels, define here
return false;
}
public function reassign(FlowInstanceStep $instanceStep, array $newAssignees): void
{
// Example: update the Slack channel
$instanceStep->assignees()->delete();
foreach($newAssignees as $chan){
FlowStepAssignee::create([
'flow_instance_step_id'=>$instanceStep->id,
'assignee_type'=>'slack_channel',
'assignee_value'=>$chan
]);
}
}
}
use MrNewport\LaravelFlow\Events\FlowActionEvent;
Event::listen(FlowActionEvent::class, function(FlowActionEvent $e){
if($e->oldStep->step_id==='manager_review' && $e->action==='approve') {
// E.g. log something or call external API
}
});