hqq / scenario
A Package for set Scenario in Laravel
0.0.2
2017-07-31 11:10 UTC
This package is not auto-updated.
Last update: 2025-02-01 02:15:27 UTC
README
-
This package compatible with Laravel
>=5
-
This package help you out to make model from database and set scenario for it.
Run the Composer update comand
$ composer require hqq/scenario
Or if you using phpStorm , you can use Tools > Composer > Add Dependency
In your config/app.php
add hqq\scenario\ScenarioServiceProvider::class,
to the end of the $providers
array
'providers' => [ Illuminate\Foundation\Providers\ArtisanServiceProvider::class, Illuminate\Auth\AuthServiceProvider::class, ... hqq\scenario\ScenarioServiceProvider::class, ],
Usage cmodel
in artisan console write
php artisan make:cmodel table_name
Example Model
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Units extends Model { static $rules = [ 'phone' => ['required|numeric|digits:11'], 'address' => ['required'], 'services' => ['required'], 'website' => ['required|regex:/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/'], 'email' => ['required|email',['mostafa']], 'description' => ['required',['mostafa']], 'about_us' => ['required', ['mehrdad']], 'picture' => ['required|image|mimes:jpg,png,gif,jpeg|max:1000', ['store','mostafa']] ]; protected $table = "units"; protected $fillable = ['picture', 'phone', 'address', 'services', 'website', 'email', 'description', 'about_us']; }
Usage Code
Scenarioo::setRules(AllowedUnits::$rules)
Scenarioo::setScenario(['store','mostafa'])
Scenarioo::Rules()
Scenarioo::setRules(Units::$rules); Scenarioo::setScenario(['store','mostafa']); $validation = \Validator::make($request->all(),Scenarioo::Rules()); if($validation->fails()){ return \Redirect::back()->withErrors($validation->errors())->withInput(); }
License
- This package was created and modified by Mostafa Haqiqi && Mehrdad Akbari for Laravel >= 5 and is released under the MIT License.