Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

php - How to use Laravel Requests in Livewire Components

How to use exactly the same rules that I use in Laravel Requests in Livewire Components? I have already build Request in Laravel and I don't want to rebuild it in Livewire. In Livewire i can't use Laravel option (e.g. AppRules). What is the best way to solve this problem because we also have api calls through controllers?

question from:https://stackoverflow.com/questions/65865623/how-to-use-laravel-requests-in-livewire-components

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You need to use rules() as a method instead of a property

use IlluminateValidationRule;


public function rules()
{
    return [
        'name' => ['required', new MyRule()],
        'content' => 'required|min:10'
    ];
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...