Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add some class rules in class Rule #44998

Merged
merged 4 commits into from Nov 18, 2022

Conversation

michaelnabil230
Copy link
Contributor

@michaelnabil230 michaelnabil230 commented Nov 17, 2022

It is the best way to call these functions password and imageFile and file, enum.

And don't call in Controller or FormValidation all namespace

Before PR:

use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password;
use Illuminate\Validation\Rules\File;
use Illuminate\Validation\Rules\Enum;

class WelcomeController
{
    public function store(Request $request)
    {
        $request->validate([
            'password' => Password::default(),
            'image' => File::default(),
            'status' => new Enum(StatusEnum::class),
            'name' => Rule::requiredIf(function () {
                return true;
            })
        ]);

        // 
    }
}

After PR:

use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

class WelcomeController
{
    public function store(Request $request)
    {
        $request->validate([
            'password' => Password::default(),
            'image' => Rule::file()->default(),
            'status' => Rule::enum(StatusEnum::class),
            'name' => Rule::requiredIf(function () {
                return true;
            })
        ]);

        // 
    }
}

@taylorotwell taylorotwell merged commit 189cec5 into laravel:9.x Nov 18, 2022
@taylorotwell
Copy link
Member

Removed the password one. The rest seems fine.

@michaelnabil230 michaelnabil230 deleted the add-rule branch November 23, 2022 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants