Skip to content

Commit a6923fa

Browse files
authored
Update README.md
1 parent 7fcd488 commit a6923fa

File tree

1 file changed

+54
-21
lines changed

1 file changed

+54
-21
lines changed

README.md

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/soap/laravel-workflow-process/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/soap/laravel-workflow-process/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain)
66
[![Total Downloads](https://img.shields.io/packagist/dt/soap/laravel-workflow-process.svg?style=flat-square)](https://packagist.org/packages/soap/laravel-workflow-process)
77

8-
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
8+
Using [Zerodahero's Laravel Workflow (based on Symfony Workflow)](https://github.com/zerodahero/laravel-workflow) to handle state-transition workflow is great. However, coding transition guard in event is hard. This package provides a simple way, you can add Symfony Expression Language as a transition guard for each transition. This configuration must provided in transiton metadata using 'guard' as a key.
9+
This package subscribes for all workflows' transition guard events and uses provided Symfony Expression Language to allow to block the transition.
910

1011
## Support us
1112

12-
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/laravel-workflow-process.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/laravel-workflow-process)
13-
14-
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
15-
16-
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
1713

1814
## Installation
1915

@@ -23,13 +19,6 @@ You can install the package via composer:
2319
composer require soap/laravel-workflow-process
2420
```
2521

26-
You can publish and run the migrations with:
27-
28-
```bash
29-
php artisan vendor:publish --tag="laravel-workflow-process-migrations"
30-
php artisan migrate
31-
```
32-
3322
You can publish the config file with:
3423

3524
```bash
@@ -43,18 +32,62 @@ return [
4332
];
4433
```
4534

46-
Optionally, you can publish the views using
47-
48-
```bash
49-
php artisan vendor:publish --tag="laravel-workflow-process-views"
50-
```
51-
5235
## Usage
36+
Task that you have to do is providing guard configuration like the following example. This is in laravel-workflow 's configuration file (config/workflow.php). If you want to store workflow configuration in database, please visis [my Laravel Workflow Loader package](https://github.com/soap/laravel-workflow-loader).
5337

5438
```php
55-
$laravelWorkflowProcess = new Prasit Gebsaap\LaravelWorkflowProcess();
56-
echo $laravelWorkflowProcess->echoPhrase('Hello, Prasit Gebsaap!');
39+
// file config/workflow.php
40+
use ZeroDaHero\LaravelWorkflow\MarkingStores\EloquentMarkingStore;
41+
42+
return [
43+
'blogPost' => [
44+
'type' => 'workflow',
45+
'supports' => [App\Models\BlogPost::class],
46+
'marking_store' => [
47+
'property' => 'state',
48+
'type' => 'single_state',
49+
'class' => EloquentMarkingStore::class,
50+
],
51+
'places' => ['draft', 'pending_for_review', 'approved', 'rejected', 'published', 'archived'],
52+
'transitions' => [
53+
'submit' => [
54+
'from' => 'draft',
55+
'to' => 'pending_for_review',
56+
'metadata' => [
57+
'guard' => 'authenticated and subject.isOwnedBy(user)',
58+
],
59+
],
60+
'approve' => [
61+
'from' => 'pending_for_review',
62+
'to' => 'approved',
63+
],
64+
'reject' => [
65+
'from' => 'pending_for_review',
66+
'to' => 'rejected',
67+
],
68+
'publish' => [
69+
'from' => 'approved',
70+
'to' => 'published',
71+
],
72+
'archive' => [
73+
'from' => ['draft', 'rejected'],
74+
'to' => 'archived',
75+
],
76+
],
77+
]
78+
79+
];
5780
```
81+
Currenty these variables/objects were injected into Symfony Expression Language.
82+
83+
- "subject" is the Eloquent model which is subject of a workflow
84+
- "user" is authenticated user.
85+
- "authenticated" boolean, true if user was authenticated.
86+
87+
So you can call any method on the injected object.
88+
89+
## Todo
90+
I have a plan to prover document role for user. For example, some users may be assign as "reviewer" or "approver" for Eloquent model. So we can use something like subject.hasActorRole('reviewer') or subject.canBeReviewedBy(user). Any suggestion is welcome.
5891

5992
## Testing
6093

0 commit comments

Comments
 (0)