Error when updating in laravel 5

0

Hello, I'm getting the error:

"SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'titu_2_ing' cannot be null (SQL: update 'sections' set 'titu_2_ing' = , 'titu_2_esp' = , 'desc_2_ing' = , 'desc_2_esp' = , 'titu_3_ing' = , 'titu_3_esp' = , 'desc_3_ing' = , 'desc_3_esp' = , 'titu_4_ing' = , 'titu_4_esp' = , 'desc_4_ing' = , 'desc_4_esp' = , 'updated_at' = 2018-03-08 18:11:06 where 'id' = 2)

As if I was sending my empty inputs and they are like this, I'll just put some inputs

<form method="POST" action="{{ route('about_update') }}">
                    {{ csrf_field() }} 
                    <input type="hidden" name="id_registro" value="2" /> <!-- Valor del registro -->
                        <!-- TITULO -->
                        <div class="row justify-content-between" style="box-shadow: 0px 0px 10px 1px rgba(0, 0, 0, 0.47);
                                                                                border-radius: 5px;
                                                                                background: #f0f3f5;
                                                                                padding: 0.7rem 0.2rem 0.2rem 0.2rem;">
                            <div class="col-6">
                                <h4 style="color: #0b4650;"><strong>ABOUT US/EDIT</strong></h4>
                            </div>
                            <div class="col-6" style="text-align: right; padding-right: 3rem;">
                                <input style="color: gray; border: none; width: 17rem; background: none;" value="ÚLTIMA EDICIÓN {{ $sectionInfo->updated_at }}" class="field left" readonly="readonly" name="updated_at">
                            </div>
                        </div>

                

                    <!-- BOTONES GUARDAR / CERRAR -->
                    <div class="row" style="    text-align: right;
                                                margin-top: 1rem;
                                                margin-bottom: 1rem;">
                        <div class="col-12">
                            <button type="button" class="btn" style="background: #065e6e; color: white; width: 7rem;">CERRAR</button>
                            <button type="SUBMIT" class="btn" style="background: #00a751; color: white; width: 7rem;">ACTUALIZAR</button>
                        </div>    
                    </div>

                    <!-- TITULOS 1-->
                    <div class="row">
                        <div class="col-6" style="padding-left: 3px; margin-bottom: 1rem;">
                            <input type="text" name="titu_1_ing" value="{{ $sectionInfo->titu_1_ing }}" style=" width: 100%;   padding: 0.3rem;   background: #e3e6e9; border: solid 1px #8181825c;">
                        </div>
                        <div class="col-6" style="padding-right: 3px; margin-bottom: 1rem;">
                            <input type="text" name="titu_1_esp" value="{{ $sectionInfo->titu_1_esp }}" style="width: 100%; padding: 0.3rem;  background: #e3e6e9; border: solid 1px #8181825c;">
                        </div>
                    </div>

                    <!-- DESCRIPCIONES 1-->
                    <div class="row">
                        <div class="col-6" style="padding-left: 3px; margin-bottom: 1rem;">
                            <textarea name="desc_1_ing" rows="30" cols="80" style=" width: 100%; padding: 0.8rem;  height: 10rem; background: #e3e6e9; border: solid 1px #8181825c;">{{ $sectionInfo->desc_1_ing }}</textarea>
                        </div>
                        <div class="col-6" style="padding-right: 3px; margin-bottom: 1rem;">
                            <textarea name="desc_1_esp" rows="30" cols="80" style=" width: 100%; padding: 0.8rem;  height: 10rem; background: #e3e6e9; border: solid 1px #8181825c;">{{ $sectionInfo->desc_1_esp }}</textarea>
                        </div>
                    </div>


                     <!-- TITULOS 2-->
                    <div class="row">
                        <div class="col-6" style="padding-left: 3px; margin-bottom: 1rem;">
                            <input type="text" name="titu_1_ing" value="{{ $sectionInfo->titu_2_ing }}" style=" width: 100%;   padding: 0.3rem;   background: #e3e6e9; border: solid 1px #8181825c;">
                        </div>
                        <div class="col-6" style="padding-right: 3px; margin-bottom: 1rem;">
                            <input type="text" name="titu_1_esp" value="{{ $sectionInfo->titu_2_esp }}" style="width: 100%; padding: 0.3rem;  background: #e3e6e9; border: solid 1px #8181825c;">
                        </div>
                    </div>

                    <!-- DESCRIPCIONES 2-->
                    <div class="row">
                        <div class="col-6" style="padding-left: 3px; margin-bottom: 1rem;">
                            <textarea name="desc_1_ing" rows="30" cols="80" style=" width: 100%; padding: 0.8rem;  height: 10rem; background: #e3e6e9; border: solid 1px #8181825c;">{{ $sectionInfo->desc_2_ing }}</textarea>
                        </div>
                        <div class="col-6" style="padding-right: 3px; margin-bottom: 1rem;">
                            <textarea name="desc_1_esp" rows="30" cols="80" style=" width: 100%; padding: 0.8rem;  height: 10rem; background: #e3e6e9; border: solid 1px #8181825c;">{{ $sectionInfo->desc_2_esp }}</textarea>
                        </div>
                    </div>

And in my routes I have

Route :: get ('about_us', 'HomeAboutController @ indexAbout') - > name ('about_us'); Route :: POST ('about_update', 'HomeAboutController @ updateus') - > name ('about_update');

so that in my updateus method I put the following:

public function updateus(Request $request)
{
    $sectionInfo = Section::find($request->get('id_registro'));
    $sectionInfo->titu_1_ing = $request->get('titu_1_ing');
    $sectionInfo->titu_1_esp = $request->get('titu_1_esp');
    $sectionInfo->desc_1_ing = $request->get('desc_1_ing');
    $sectionInfo->desc_1_esp = $request->get('desc_1_esp');

    $sectionInfo->titu_2_ing = $request->get('titu_2_ing');
    $sectionInfo->titu_2_esp = $request->get('titu_2_esp');
    $sectionInfo->desc_2_ing = $request->get('desc_2_ing');
    $sectionInfo->desc_2_esp = $request->get('desc_2_esp');

    $sectionInfo->titu_3_ing = $request->get('titu_3_ing');
    $sectionInfo->titu_3_esp = $request->get('titu_3_esp');
    $sectionInfo->desc_3_ing = $request->get('desc_3_ing');
    $sectionInfo->desc_3_esp = $request->get('desc_3_esp');

    $sectionInfo->titu_4_ing = $request->get('titu_4_ing');
    $sectionInfo->titu_4_esp = $request->get('titu_4_esp');
    $sectionInfo->desc_4_ing = $request->get('desc_4_ing');
    $sectionInfo->desc_4_esp = $request->get('desc_4_esp');
    $sectionInfo->save();
    return redirect('about_us');
}

The strange thing is that I already did this same thing but with another view so that everything is almost the same except that it has id = 2, I read the doc of laravel to see if I should put a key in the model and said that if it has an id field takes it automatically as a primary key so I do not know what could be happening

    
asked by Naoto Amari 08.03.2018 в 19:21
source

1 answer

0

The problem is that the names of the input / text area from the second have the same name as the first example:

<input type="text" name="titu_1_ing" value="{{ $sectionInfo->titu_2_ing }}" style=" width: 100%;   padding: 0.3rem;   background: #e3e6e9; border: solid 1px #8181825c;">

instead of

<input type="text" name="titu_2_ing" value="{{ $sectionInfo->titu_2_ing }}" style=" width: 100%;   padding: 0.3rem;   background: #e3e6e9; border: solid 1px #8181825c;">

and so for others that's why you mark the error is as if you sent only the titles and description 1

    
answered by 09.03.2018 в 01:16