I have a User table, which among its variables has a call balance, which is of integer type and is to indicate how much money a user has. I want to make a form which the user writes a number. If the user's balance is zero (or equal to 0), this number will be added as a balance, but if it already had a balance, it will be added to its current amount.
Form:
@extends('layouts.app')
@section('content')
@Logged()
@include('partials.errors')
<form method="POST" action="../saldo">
{{ csrf_field() }}
<div class="form-group">
<label for="saldo" class="col-md-12 control-label"> {{ __("Saldo actual") }}
</label>
<input id="saldo" class="form-control" name="saldo" value="{{ old('saldo') }}"/>
</div>
<button type="submit" name="addSaldo" class="btn btn-default"> {{ __("Ingresar saldo") }}
</button>
</form>
@else
<h1 class="text-center text-mute" style="color:#FF0000"> {{ __("¡DEJA DE HACER EL INDIO Y INICIA SESIÓN!") }} </h1>
@endLogged
@endsection
web.php:
Route::get('/saldo','UserController@store');
And in method in UserController.php:
public function store(Request $request){
$normas=[
'saldo' => 'required',
];
$this->validate($request,$normas);
if(empty(Auth::user()->saldo))
Auth::user()->saldo=$request->$saldo;
else
Auth::user()->saldo+=$request->$saldo;
Auth::user()->save();
return back()->with('message', ['success', __("Su ingreso se ha efectuado con exito.")]);
}
But I run the form and I run into this.
And if I put in the first line of store () something like dd ("Ready") I also get the error message. It works if I access directly instead of through the form, so I guess the error is in the form.