Driver laravel does not update

3

I have a problem when I try to update the information, when I press the btn to edit the information, I load a view with the text fields that get information from the table, but when I edit them and try to submit, the request errors, for example in the ruc attribute I have defined in the request as required|numeric|max:13 and when submitting the form with the data already entered, it appears on the screen that the field must be entered or that be numeric, that is, it's like if my form sends the various fields and skips the alerts. even if I do not edit the information in the table and I do the submit with the same information, the alerts do jump.

Table that I intend to update

This is what it shows when you update

To get to that view I press the edit button that is in the index this is the code.

<a href="/info_junta/{{$i->idjunta}}/edit" class="btn btn-success"><li class="fa fa-edit"></li>&nbsp; Editar información</a>

Driver

<?php

namespace juntaAgua\Http\Controllers;

use juntaAgua\InfoJunta;
use juntaAgua\Http\Requests\InfoJuntaRequest;


use Illuminate\Http\Request;

use juntaAgua\Http\Requests;
use DB;

use Response;
use Illuminate\Support\Facades\Input;

class MantenimientoController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {


        if ($request) {
            $query = DB::table('junta')
                ->where('idjunta', '=', '1')
                ->get();
            return view('mantenimiento.info_junta', ["infoJunta" => $query]);
        } else {
            return 'No existe informacion referente a la Junta';
        }
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        return view('mantenimiento.edit_junta', ["infoJunta" => InfoJunta::findOrFail($id)]);
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function update(InfoJuntaRequest $request, $id)
    {



        $infoJunta = InfoJunta::findOrFail($id);
        $infoJunta->nombre = $request->get('nombre');
        $infoJunta->mision = $request->get('mision');
        $infoJunta->vision = $request->get('vision');
        $infoJunta->ruc = $request->get('ruc');
        $infoJunta->logo = $request->get('logo');
        $infoJunta->update();

        return Redirect::to('/info_junta');

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        return 'intento delete!';
    }
}

Request

<?php

namespace juntaAgua\Http\Requests;

use juntaAgua\Http\Requests\Request;

class InfoJuntaRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'nombre'=>'required|max:100',
            'info'=>'max:500',
            'logo'=>'max:100',
            'ruc'=>'required|max:13|numeric',
            'mision'=>'max:500',
            'vision'=>'max:500'
        ];
    }
}

Form for editing

@extends('layouts.admin')
@section('contenido')
    <div id="lol">
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">Datos informativos de la Junta Administradora de Agua</div>
                    <div class="panel-body">
                        @if(count($errors)>0)
                            <div class="alert alert-danger">
                                <ul>
                                    @foreach($errors->all() as $error)
                                        <li>{{$error}}</li>
                                    @endforeach
                                </ul>

                            </div>
                        @endif
                        <div class="row">
                            {!!Form::model($infoJunta,['method'=>'patch','route'=>['info_junta.destroy',$infoJunta->idjunta]])!!}
                            {{Form::token()}}
                            <div class="form-group has-success">

                                <div class="col-lg-6 col-sm-6 col-md-6 col-xs-6">
                                    <label for="">IdJunta</label>
                                    <input disabled type="text" class="form-control" value="{{$infoJunta->idjunta}}">
                                </div>

                                <div class="col-lg-6 col-sm-6 col-md-6 col-xs-6">
                                    <label for="">Ruc</label>
                                    <input type="number" class="form-control" name="ruc" value="{{$infoJunta->ruc}}">
                                </div>
                                <div class="col-lg-12">
                                    <label for="">Nombre de la Junta</label>
                                    <input type="text" class="form-control" name="nombre"
                                           value="{{$infoJunta->nombre}}">

                                </div>
                                <div class="col-lg-6">
                                    <label for="">Misión</label>
                                <textarea class="form-control" name="mision" id="" cols="30"
                                          rows="10">{{$infoJunta->mision}}</textarea>
                                </div>
                                <div class="col-lg-6">
                                    <label for="">Visión</label>
                                <textarea class="form-control" name="vision" id="" cols="30"
                                          rows="10">{{$infoJunta->vision}}</textarea>
                                </div>
                                <div class="col-lg-12">
                                    <label for="">Foto</label>
                                    <input type="file" class="form-control" name="foto" value="{{$infoJunta->logo}}">
                                </div>

                            </div>


                        </div>
                    </div>

                    <div class="panel-footer text-center">
                        <button class="btn btn-success" type="submit">
                            <li class="fa fa-save"></li>
                            &nbsp;Actualizar
                        </button>
                        {!!Form::close()!!}
                        <a href="/info_junta" class="btn btn-default"><li class="fa fa-times"></li>&nbsp;Cancelar</a>



                    </div>




                </div>
            </div>
        </div>


    </div>








@endsection

Route.php

Route::resource('/info_junta','MantenimientoController');

php artisan route: list

|        | GET|HEAD  | info_junta/create                | info_junta.create        | juntaAgua\Http\Controllers\MantenimientoController@create      | web        |
|        | GET|HEAD  | info_junta/{info_junta}          | info_junta.show          | juntaAgua\Http\Controllers\MantenimientoController@show        | web        |
|        | PUT|PATCH | info_junta/{info_junta}          | info_junta.update        | juntaAgua\Http\Controllers\MantenimientoController@update      | web        |
|        | DELETE    | info_junta/{info_junta}          | info_junta.destroy       | juntaAgua\Http\Controllers\MantenimientoController@destroy     | web        |
|        | GET|HEAD  | info_junta/{info_junta}/edit     | info_junta.edit          | juntaAgua\Http\Controllers\MantenimientoController@edit        | web        |
    
asked by jeancarlos733 19.04.2017 в 10:15
source

1 answer

2

I think you're misusing the validation of max:13 . As the documentation says this rule validates a specific number, not the length of the field, in integers.

link

  

The number 1800567323 is greater than 13.

If you want to validate the number of digits, you can use digits:13 if the number always has 13 digits, or digits_between:1,13 assuming they are allowed between 1 and 13 digits.

link

    
answered by 19.04.2017 / 19:02
source