N
N
Nikita Dergachov2017-08-15 12:53:12
Laravel
Nikita Dergachov, 2017-08-15 12:53:12

How to insert variable into laravel validation rule?

There is validation:

$v = Validator::make($this->request->all(), [
            'type' => 'required|in:1,2,3,4',
        ]);

I want to replace the numbers with constants for clarity.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2017-08-15
@vanillathunder

Well, right in the documentation , your task is solved.

A
Alexander Aksentiev, 2017-08-15
@Sanasol

$v = Validator::make($this->request->all(), [
            'type' => 'required|in:1,2,3,'.$peremennaya,
        ]);

$v = Validator::make($this->request->all(), [
            'type' => "required|in:1,2,3,{$peremennaya}",
        ]);

$v = Validator::make($this->request->all(), [
            'type' => "required|in:".implode(',', $massiv_peremennih),
        ]);

and a thousand and one more ways

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question