0

This is the code of my Laravel Validator , Whatever I do , The browser responds with "Bye" What's wrong?

public function store()
{
    $validator = Validator::make(
    [Input::get('title'),Input::get('body')],
    [Input::get("title") => 'required|min:5',Input::get("body") => 'required|min:5']
    );

    if ($validator->fails()) {
        return "Bye";
    }
}

2 Answers 2

1

Error is in this line

[Input::get('title'),Input::get('body')]
[Input::get("title") => 'required|min:5',Input::get("body") => 'required|min:5']

you are using input field value not input field, so there is no rule attached on value name so replace this with

Input::only('title','body')
['title' => 'required|min:5', 'body' => 'required|min:5']
Sign up to request clarification or add additional context in comments.

Comments

0

You had problems in two parts of your code and this one might work for you.

public function store()
{
    $validator = Validator::make(
        Input::only('title','body'),
        ['title' => 'required|min:5','body' => 'required|min:5']
    );

    if ($validator->fails()) {
        return "Bye";
    }
}

The problems were in rules

[Input::get('title'),Input::get('body')],

This is not the way you should pass them, you need an associative array, so you have two options:

['title' => Input::get('title'), 'body' => Input::get('body')],

or

Input::only('title','body'),

And you were not passing the fields names, but the input values

[Input::get("title") => 'required|min:5',Input::get("body") => 'required|min:5']

This would be the way to pass the fields names:

['title' => 'required|min:5', 'body' => 'required|min:5']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.