P
P
Pro_Code2020-11-26 21:21:41
Laravel
Pro_Code, 2020-11-26 21:21:41

Laravel is it possible to somehow pull out a variable?

How to pull the min variable in layout?

class MyformRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'email'=>'required|min:6',
            'password'=>'required|min:6',
        ];
    }

    public function messages()
    {
        return [
            'email.required' => 'Поле Email не должно быть пустым',
            'email.min' => 'Поле Email должно содержать не менее :min символов',
            'password.required' => 'Пароль не введен',
            'password.min' => 'Поле Password содержит менее :min символов',
        ];
    }

}

layout code:
<input type="password" name="password" class="form-control" id="password"
       placeholder="Enter password">
<small id="emailHelp" class="form-text text-muted">*не менее 6 символов.</small>

The question is, is it possible to somehow take the :min variable and substitute something like this:
<input type="password" name="password" class="form-control" id="password"
       placeholder="Enter password">
<small id="emailHelp" class="form-text text-muted">*не менее {{':min'}} символов.</small>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
HabrDima20, 2020-11-26
@HabrDima20

function __construct() {
     $min = 6
   }

public function rules()
    {
        return [
            'email'=>'required|min:$min',
            'password'=>'required|min:$min',
        ];
    }

return view('layout', compact('min'))
<input type="password" name="password" class="form-control" id="password"
       placeholder="Enter password">
<small id="emailHelp" class="form-text text-muted">*не менее {{$min}} символов.</small>

T
the5x, 2020-11-29
@the5x

Maybe it's better to do @error('email'){{ $message }}@enderror

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question