66[ ![ MIT Licensed] ( https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square )] ( LICENSE.md )
77
88### Introduction
9- Solum DeSignum Scenarios is agnostic backend validation Scenarios package.
9+ Scenarios are agnostic backend validation Scenarios package.
1010
1111
1212### Installation
@@ -21,9 +21,10 @@ Next, publish Scenarios resources using the vendor:publish command:
2121php artisan vendor:publish --provider=" SolumDeSignum\Scenarios\ScenariosServiceProvider"
2222```
2323
24- This command will publish Scenarios config to your config directory, which will be
25- created if it does not exist.
24+ This command will publish scenarios.php config to your config directory, which will be created if it does not exist.
2625
26+ ### Upgrade from v1.xx to version v2.00
27+ [ UPGRADE_V2.md] ( UPGRADE_V2.md ) !!!
2728
2829### Scenarios Features
2930The Scenarios configuration file contains a configuration array.
@@ -34,16 +35,132 @@ declare(strict_types=1);
3435
3536return [
3637 'features' => [
37- 'setMethodFromUrlSegment' => false,
38- 'setMethodFromController' => true,
38+ 'set_method' => [
39+ 'from' => [
40+ 'controller' => true,
41+ 'url_segment' => false,
42+ ],
43+ 'exceptions' => [
44+ 'controller' => true
45+ ],
46+ ],
3947 ],
4048 'methods' => [
41- 'pattern' => '/create|store|update|destroy/im'
42- ]
49+ 'pattern' => '/create|store|update|destroy/im',
50+ ],
4351];
4452````
4553
46- ### Scenario's With Form Request Validation
54+ ### Scenario's with Controller
55+ Before using it must change config
56+ ```php
57+ <?php
58+
59+ declare(strict_types=1);
60+
61+ return [
62+ 'features' => [
63+ 'set_method' => [
64+ 'from' => [
65+ 'controller' => true,
66+ 'url_segment' => false,
67+ ],
68+ 'exceptions' => [
69+ 'controller' => false
70+ ],
71+ ],
72+ ],
73+ 'methods' => [
74+ 'pattern' => '/create|store|update|destroy/im',
75+ ],
76+ ];
77+ ````
78+ Now we are prepared to use it in controller.
79+ ```php
80+ <?php
81+
82+ declare(strict_types=1);
83+
84+ namespace App\Http\Controllers;
85+
86+ use Illuminate\Http\Request;
87+ use SolumDeSignum\Scenarios\Traits\Scenarios;
88+
89+ class ExampleControler extends Controller
90+ {
91+ use Scenarios;
92+
93+ /**
94+ * Display a listing of the resource.
95+ */
96+ public function index(): void
97+ {
98+ dump($this);
99+ dd($this->scenario);
100+ }
101+
102+ /**
103+ * Show the form for creating a new resource.
104+ */
105+ public function create(): void
106+ {
107+ if ($this->scenario === 'create') {
108+ // my logic
109+ }
110+ }
111+
112+ /**
113+ * Store a newly created resource in storage.
114+ */
115+ public function store(Request $request): void
116+ {
117+ if ($this->scenario === 'store') {
118+ // my logic
119+ }
120+ }
121+
122+ /**
123+ * Display the specified resource.
124+ */
125+ public function show(string $id): void
126+ {
127+ dump($this);
128+ dd($this->scenario);
129+ }
130+
131+ /**
132+ * Show the form for editing the specified resource.
133+ */
134+ public function edit(string $id): void
135+ {
136+ dump($this);
137+ dd($this->scenario);
138+ }
139+
140+ /**
141+ * Update the specified resource in storage.
142+ */
143+ public function update(Request $request, string $id): void
144+ {
145+ if ($this->scenario === 'update') {
146+ // my logic
147+ }
148+ }
149+
150+ /**
151+ * Remove the specified resource from storage.
152+ */
153+ public function destroy(string $id): void
154+ {
155+ if ($this->scenario === 'destroy') {
156+ // my logic
157+ }
158+ }
159+ }
160+ ````
161+
162+ ### Scenario's with your Form Request Validation
163+
47164```php
48165<?php
49166
@@ -53,8 +170,7 @@ namespace App\Http\Requests;
53170
54171use Illuminate\Foundation\Http\FormRequest;
55172use Illuminate\Support\Facades\Auth;
56- use SolumDeSignum\Scenarios\Scenarios;
57-
173+ use SolumDeSignum\Scenarios\Traits\Scenarios;
58174
59175class OfficeBlogRequest extends FormRequest
60176{
@@ -110,11 +226,10 @@ class OfficeBlogRequest extends FormRequest
110226
111227### Validation Rules Usage
112228#### However, can be used on both examples
229+
113230```php
114231namespace App\Validation;
115232
116- use SolumDeSignum\Scenarios\Scenarios;
117-
118233class SampleRules
119234{
120235 public static function ScenarioRules(string $scenario): ?array
@@ -141,16 +256,17 @@ class SampleRules
141256
142257### Scenario's With Controller
143258#### Manually Creating Validators
259+
144260``` php
145261<?php
146262
147263declare(strict_types=1);
148264
149265namespace App\Http\Controllers\Office\Blog;
150266
151- use Illuminate\Support\Facades\Validator;
152- use SolumDeSignum\Scenarios\Scenarios;
153267use App\Validation\SampleRules;
268+ use Illuminate\Support\Facades\Validator;
269+ use SolumDeSignum\Scenarios\Traits\Scenarios;
154270
155271class BlogController
156272{
0 commit comments