https://github.com/solumdesignum/scenarios
Solum DeSignum Scenarios is agnostic backend validation Scenarios package.
https://github.com/solumdesignum/scenarios
develoment githunt laravel laravel-scenarios opensource opensourcedevelopment package packages php php7 scenarios solumdesignum
Last synced: 3 months ago
JSON representation
Solum DeSignum Scenarios is agnostic backend validation Scenarios package.
- Host: GitHub
- URL: https://github.com/solumdesignum/scenarios
- Owner: SolumDeSignum
- License: mit
- Created: 2018-08-24T00:27:04.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2024-10-18T21:26:59.000Z (12 months ago)
- Last Synced: 2025-03-25T09:49:28.339Z (7 months ago)
- Topics: develoment, githunt, laravel, laravel-scenarios, opensource, opensourcedevelopment, package, packages, php, php7, scenarios, solumdesignum
- Language: PHP
- Homepage: https://solum-designum.eu/
- Size: 35.2 KB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://github.styleci.io/repos/145921620)
[](https://scrutinizer-ci.com/g/SolumDeSignum/scenarios/?branch=master)
[](https://packagist.org/packages/solumdesignum/scenarios)
[](https://packagist.org/packages/solumdesignum/scenarios)
[](https://packagist.org/packages/solumdesignum/scenarios)
[](LICENSE.md)### Introduction
Scenarios are agnostic backend validation Scenarios package.### Installation
To get started, install Scenarios using the Composer package manager:
```shell
composer require solumdesignum/scenarios
```Next, publish Scenarios resources using the vendor:publish command:
```shell
php artisan vendor:publish --provider="SolumDeSignum\Scenarios\ScenariosServiceProvider"
```This command will publish scenarios.php config to your config directory, which will be created if it does not exist.
### Upgrade from v1.xx to version v2.00
[UPGRADE_V2.md](UPGRADE_V2.md) !!!### Scenarios Features
The Scenarios configuration file contains a configuration array.
```php
[
'set_method' => [
'from' => [
'controller' => true,
'url_segment' => false,
],
'exceptions' => [
'controller' => true
],
],
],
'methods' => [
'pattern' => '/create|store|update|destroy/im',
],
];
````### Scenario's with Controller
Before using it must change config
```php
[
'set_method' => [
'from' => [
'controller' => true,
'url_segment' => false,
],
'exceptions' => [
'controller' => false
],
],
],
'methods' => [
'pattern' => '/create|store|update|destroy/im',
],
];
````
Now we are prepared to use it in controller.
```php
scenario);
}/**
* Show the form for creating a new resource.
*/
public function create(): void
{
if ($this->scenario === 'create') {
// my logic
}
}/**
* Store a newly created resource in storage.
*/
public function store(Request $request): void
{
if ($this->scenario === 'store') {
// my logic
}
}/**
* Display the specified resource.
*/
public function show(string $id): void
{
dump($this);
dd($this->scenario);
}/**
* Show the form for editing the specified resource.
*/
public function edit(string $id): void
{
dump($this);
dd($this->scenario);
}/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id): void
{
if ($this->scenario === 'update') {
// my logic
}
}/**
* Remove the specified resource from storage.
*/
public function destroy(string $id): void
{
if ($this->scenario === 'destroy') {
// my logic
}
}
}
````### Scenario's with your Form Request Validation
```php
scenario === 'store') {
$rules = [
'title' => 'required|string',
'publish_at' => 'required',
'blog_category_id' => 'required|numeric',
'description' => 'required',
];
}if ($this->scenario === 'update') {
$rules = [
'title' => 'required|string',
'publish_at' => 'required',
'blog_category_id' => 'required|numeric',
'description' => 'required',
'img' => 'image',
];
}if ($this->scenario === 'destroy') {
$rules = [];
}return $rules;
}
}
````### Validation Rules Usage
#### However, can be used on both examples```php
namespace App\Validation;
class SampleRules
{
public static function ScenarioRules(string $scenario): ?array
{
switch ($scenario) {
case $scenario === 'store';
return
[
'text' => 'required|string',
];
break;case $scenario === 'update';
return
[
'text' => 'required|string',
'description' => 'required|string',
];
break;
}
}
}
```### Scenario's With Controller
#### Manually Creating Validators```php
all(), SampleRules::ScenarioRules($this->scenario));
if ($validator->passes()) {
#Your Logic Code
}
}
}
```### Controller Functions Names Examples
#### However, you can override regex with your naming conventions inside configuration
```php
[
'pattern' => '/create|store|update|destroy/im'
]
];#Controller Function Naming Samples: create(), store() , update() , destroy()
```Author
-------
- [Oskars Germovs](http://solum-designum.eu) ([Twitter](https://twitter.com/faksx))Support
-------
If you need support you can ask on [Twitter](https://twitter.com/faksx).License
-------
Solum DeSignum Scenarios is open-sourced software licensed under the [MIT license](LICENSE.md).