PHP code example of gabrieljmj / laravel-rule-sets
1. Go to this page and download the library: Download gabrieljmj/laravel-rule-sets 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/ */
namespace App\Rules\RuleSets;
use Gabrieljmj\LaravelRuleSets\AbstractRuleSet;
class UserRuleSet extends AbstractRuleSet
{
protected function rules(): array
{
return [
'username' => '
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use App\Rules\RuleSets\UserRuleSet;
class UserRequest extends FormRequest
{
// ...
public function rules(UserRuleSet $userRules)
{
return $userRules->getRules();
}
}
use App\Rules\RuleSets\UserRuleSet;
use App\Rules\RuleSets\PasswordRuleSet;
// ...
public function rules(UserRuleSet $userRules, PasswordRuleSet $passwordRuleSet)
{
return $userRules
->combineWith([$passwordRuleSet])
->getRules();
}
namespace App\Rules\RuleSets;
use Gabrieljmj\LaravelRuleSets\AbstractRuleSet;
class PersonRuleSet extends AbstractRuleSet
{
protected function rules(): array
{
return [
'name' => '
namespace App\Rules\RuleSets;
use Gabrieljmj\LaravelRuleSets\AbstractRuleSet;
class UserRuleSet extends AbstractRuleSet
{
public function __construct(PersonRuleSet $personRuleSet)
{
// Adds other rule set
$this->combineWith[] = $personRuleSet;
}
protected function rules(): array
{
return [
'email' => '