Giter Site home page Giter Site logo

shamielo / filament-workflows Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tschucki/filament-workflows

0.0 0.0 0.0 204 KB

Laravel Filament plugin to add workflows. Attach triggers and dispatchable actions to automate tasks

License: MIT License

JavaScript 6.90% PHP 92.86% CSS 0.24%

filament-workflows's Introduction

Add workflows to your filament app

Latest Version on Packagist GitHub Tests Action Status Fix PHP Code Styling Total Downloads

This plugin lets you add workflows to your filament app. You can attach triggers and dispatchable actions to your workflows. The plugin will automatically execute the actions when the trigger conditions are met.

Table of Contents

Images

Screenshot 1 Screenshot 2 Screenshot 3

Installation

You can install the package via composer:

composer require tschucki/filament-workflows

You can install the plugin using:

php artisan filament-workflows:install

You can publish and run the migrations manually with:

php artisan vendor:publish --tag="filament-workflows-migrations"
php artisan migrate

Register the plugin in your AdminPanelServiceProvider:

use Tschucki\FilamentWorkflows\FilamentWorkflowsPlugin;

->plugins([
    FilamentWorkflowsPlugin::make()
])

Usage

Basics

In order to let your models use workflows, you need to add the InteractsWithWorkflows trait to your model. By adding this trait, the plugin will automatically add a global observer to your model. So when ever a workflow matches the event and trigger conditions, the workflow will execute the actions.

Add the trait to your model

use Tschucki\FilamentWorkflows\Concerns\InteractsWithWorkflow;

class User extends Model {
  use InteractsWithWorkflow;
}

Create an Action

In order to attach an action to your workflows, you will have to create a class within the App\Jobs\Actions folder. The class must extend the BaseAction class. This requires you to implement the handle method. This method will be called when the workflow is executed.

The action class is very similar to a job. When ever the action get executed, the model will be passed to the __construct method. You can use the model to do whatever you want.

The plugin will find this class on its own. So you don't have to register it anywhere.

<?php

namespace App\Jobs\WorkflowActions;

use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Tschucki\FilamentWorkflows\WorkflowActions\BaseAction;

class TestAction extends BaseAction
{
    public User $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function handle(): void
    {
        \Log::info($this->user->name . ' was created at ' . $this->user->created_at);
    }
    
    // Will be later used in the Logs (coming soon) 
    public function getActionName(): string
    {
        return 'Der Hackfleisch hassender Zerhacker';
    }

    public function getActionDescription(): string
    {
        return 'Schneidet Kopfsalat. Und das nachts :)';
    }

    public function getActionCategory(): string
    {
        return 'Default-Category';
    }

    public function getActionIcon(): string
    {
        return 'heroicon-o-adjustments';
    }
}

That's it. Now you can create and attach actions to your workflows.

Configuration

Define searchable field

If you don't just want to search for the id, you can use the function getTitleColumnForWorkflowSearch within your model to search in another field as well.

    public function getTitleColumnForWorkflowSearch(): ?string
    {
        return 'name';
    }

Max Search Results

In case you want to change the max search results for the models, you can publish the config file and change the workflows.search.max_results value (defaults to 100). This can come in handy when you have a lot of models and the search is slow.

<?php

return [
    'search' => [
        'max_results' => 100,
    ]
];

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

filament-workflows's People

Contributors

tschucki avatar dependabot[bot] avatar github-actions[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.