Skip to content

this package help you out to choose a part of rules for each work like create, update or ... and have different rules structure then you can create from command line. read whole readme file and enjoy!

License

Notifications You must be signed in to change notification settings

Mr-Hqq/Scenario

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scenario For Laravel

  • 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.

About

this package help you out to choose a part of rules for each work like create, update or ... and have different rules structure then you can create from command line. read whole readme file and enjoy!

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages