UPDATE Laravel from the view

0

I have a view that brings me the data of my db

then what I want now is to update my db

 <div class="col-10" id="side2">

            <div class="container" style="background-color: #e3e6e9; margin-top: 1rem; height:95%; padding: 2rem 1rem 1rem 1rem;">
                <div class="container" style="background-color: #f0f3f5; height: 100%; border-radius: 5px 5px 0px 0px;">

                    <!-- TITLO -->
                    <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>HOME/EDIT</strong></h4>
                        </div>

                        <div class="col-6" style="text-align: right; padding-right: 3rem;">
                            <p style="color:gray;">ÚLTIMA EDICIÓN {{ $sectionInfo->updated_at }}</p>
                        </div>
                    </div>

                    <!-- ___________________FORMULARIO___________________ -->
                    <form method="POST" action="{{ route('home') }}">

                        <!-- 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 -->
                        <div class="row">
                            <div class="col-6" style="padding-left: 3px; margin-bottom: 1rem;">
                                <input type="text" value="{{ $sectionInfo->titu_1_ing }}" style=" width: 100%;   padding: 0.3rem;   background: #e3e6e9;
                                                                                        border: solid 1px #8181825c;" text="PRIVATE ESCRUSSION IN SANTIAGO DE CHILE">
                            </div>
                            <div class="col-6" style="padding-right: 3px; margin-bottom: 1rem;">
                                <input type="text" value="{{ $sectionInfo->titu_1_esp }}" style="width: 100%; padding: 0.3rem;  background: #e3e6e9;
                                                                                    border: solid 1px #8181825c;">
                            </div>
                        </div>

                        <!-- DESCRIPCION -->
                        <div class="row">
                            <div class="col-6" style="padding-left: 3px; margin-bottom: 1rem;">
                                <textarea name="message" 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="message" 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>

                        <hr/>
                        
                        <!-- CARGAR IMAGENES -->
                        <div class="row">
                            <div class="col-6">
                                <h4>IMÁGENES DESKTOP</h4>
                            </div>

                            <div class="col-6">
                                <h4>IMÁGENES MÓVIL</h4>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-6">
                                <input type="file" id="files" name="files[]" />
                                <br />
                                <div style="width: 5rem; height: 5rem;">
                                        <output id="list"></output>
                                </div>
                            </div>
                            <div class="col-6">
                                <input type="file" id="files" name="files[]" />
                                <br />
                                <output id="list"></output>
                            </div>
                        </div>

and this is my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Section;

class HomeController extends Controller
{
    public function index()
    {
        $sectionInfo = Section::find(1);
        // let hora = $sectionInfo->updated_at;
        // hora = hora[9];
        // $sectionInfo->updated_at = hora;
        return view("home", compact('sectionInfo'));
    }

Ignore the part of the images I'm still working on it, what I need to know is how to update my fields in the db ????

**

UPDATE

** I did the following, from my view I made the normal form with the input that is called the same as my columns,

<form method="POST" action="{{ route('home_update') }}">
					    {{ csrf_field() }} 
		                    <!-- 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>HOME/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 -->
                        <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>

                        <!-- DESCRIPCION -->
                        <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>

                        <hr/>
                        
                        <!-- CARGAR IMAGENES -->
                        <div class="row">
                            <div class="col-6">
                                <h4>IMÁGENES DESKTOP</h4>
                            </div>

                            <div class="col-6">
                                <h4>IMÁGENES MÓVIL</h4>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-6">
                                <input type="file" id="files" name="files[]" />
                                <br />
                                <div>
                                        <output id="list"></output>
                                </div>
                            </div>
                            <div class="col-6">
                                <input type="file" id="files" name="files[]" />
                                <br />
                                <div>
                                	<output id="list"></output>
                                </div>
                            </div>
                        </div>
            		</form>

all right up there, then that form calls the route Route :: POST ('home_update', 'HomeController @ update') - > name ('home_update');

and in that method I have the following:

public function update(Request $request)
{
        $sectionInfo = Section::find(1);
        $section->titu_1_ing = request('titu_1_ing');
        $section->titu_1_esp = request('titu_1_esp');
        $section->desc_1_ing = request('desc_1_ing');
        $section->desc_1_esp = request('desc_1_esp');
        $section->save();
    return "Ok";
}

I feel that something is missing because I get the following error: "Parse error: syntax error, unexpected 'Section' (T_STRING), expecting ')'"

and point to the following line:   public function update (Request $ request Section $ sectionInfo)

and if I remove the Section and the $ sectionInfo it tells me the following: "Creating default object from empty value"

and point to the line

$ section- > titu_1_ing = request ('titu_1_ing') ;

    
asked by Naoto Amari 07.03.2018 в 17:48
source

1 answer

0

I think there is some part of the code that you have not put in your question, but the problem is in the error messages that you copied.

  

I feel something is missing because I get the following error: "Parse error:   syntax error, unexpected 'Section' (T_STRING), expecting ')' "

     

and point to the following line: public function update (Request $ request   Section $ sectionInfo)

What you have to do is on the line where you mark the error
public function update(Request $request Section $sectionInfo)
you have to modify it by% public function update(Request $request, Section $sectionInfo) .

The error of unespected Section is because you are missing the coma .

    
answered by 26.03.2018 / 08:14
source