Error using validations

1

Veran I want to allow a user to enter money in a variable 'balance', for which I have the following form:

@extends('layouts.app')
@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Ingresar dinero</div>

                <div class="card-body">
                    <form method="POST" action="saldo">
                        @csrf

                        <div class="form-group row">
                            <label for="dinero" class="col-md-4 col-form-label text-md-right">Dinero ingresado</label>

                            <div class="col-md-6">
                                <input id="dinero" type="number" class="form-control{{ $errors->has('dinero') ? ' is-invalid' : '' }}" name="dinero" value="{{ old('dinero') }}" required autofocus>

                                @if ($errors->has('dinero'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('dinero') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    Realizar ingreso
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

Which will be used in the following method:

public function sumar(IngresoRequest $request){
    auth()->user()->saldo+=$request->dinero;
    auth()->user()->save();
    return redirect('/')->with('message',['success','Su ingreso se ha realizado con exito.']);
}

And I also have the validation file IngresoRequest.php:

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

    public function messages(){
        return[
            'dinero.request'=>'Es obligatorio indicar cuanto dinero ingresa',
            'dinero.integer'=>'Error de formato',
            'dinero.min'=>'Debes incluir 10000€ como mínimo'
        ];
    }

    public function rules(){
        return[
            'dinero'=>'request|integer|min:10000'
        ];
    }
}

However, at the minimum I try to make the deposit, I run into this:

If I use a normal Request instead of IngressRequest if it works, so the error must be in this validator. Does anyone know what I'm doing wrong?

    
asked by Miguel Alparez 29.05.2018 в 17:47
source

1 answer

2

Your error is very simple, you are passing a validation that does not exist:

public function rules(){
    return[
        'dinero'=>'request|integer|min:10000'
    ];
}

It should be like this:

public function messages(){
    return[
        'dinero.required'=>'Es obligatorio indicar cuanto dinero ingresa',
        'dinero.integer'=>'Error de formato',
        'dinero.min'=>'Debes incluir 10000€ como mínimo'
    ];
}

public function rules(){
    return[
        'dinero'=>'required|integer|min:10000'
    ];
}

Change the word request by required

    
answered by 29.05.2018 / 17:50
source