1. Go to this page and download the library: Download solumdesignum/scenarios 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/ */
declare(strict_types=1);
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use SolumDeSignum\Scenarios\Traits\Scenarios;
class ExampleControler extends Controller
{
use Scenarios;
/**
* Display a listing of the resource.
*/
public function index(): void
{
dump($this);
dd($this->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
}
}
}
declare(strict_types=1);
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use SolumDeSignum\Scenarios\Traits\Scenarios;
class OfficeBlogRequest extends FormRequest
{
use Scenarios;
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return Auth::check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
$rules = [];
if ($this->scenario === 'store') {
$rules = [
'title' => '
namespace App\Validation;
class SampleRules
{
public static function ScenarioRules(string $scenario): ?array
{
switch ($scenario) {
case $scenario === 'store';
return
[
'text' => ' ];
break;
}
}
}
declare(strict_types=1);
namespace App\Http\Controllers\Office\Blog;
use App\Validation\SampleRules;
use Illuminate\Support\Facades\Validator;
use SolumDeSignum\Scenarios\Traits\Scenarios;
class BlogController
{
use Scenarios;
public function store(Request $request)
{
$validator = Validator::make($request->all(), SampleRules::ScenarioRules($this->scenario));
if ($validator->passes()) {
#Your Logic Code
}
}
}