Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix edit interface getting only first word of a column in table in Laravel 5.7?

Tags:

php

laravel

My edit interface edit.blade.php only gets the first word of the name from my database, this is what the index.blade.php looks like enter image description here

and when i click on the edit icon of the 3rd line it leads me to edit.blade.php which gives me this

enter image description here

"Nom d'établissement" textfield only gets the first word from the database

Everything looks fine in the database: enter image description here

this is my edit.blade.php form:

     <form method="post" action="{{ route('etablissements.update', $etablissement->id) }}">
        @method('PATCH')
        @csrf
        <div class="col-5">
        <div class="form-group">
          <label for="nom">Nom Etablissement :</label>
          <input type="text" class="form-control" name="nom" value={{ $etablissement->nom }} />
        </div>
        <div class="form-group">
          <label for="price">E-Mail :</label>
             <input type="text" class="form-control" name="email" value={{ $etablissement->email }} />
        </div>
        <div class="form-group">
          <label for="quantity">Telephone:</label>
          <input type="text" class="form-control" name="telephone" value={{ $etablissement->telephone }} />
        </div>
      </div>
          <button type="submit" class="btn btn-primary">Confirmer</button>
      </form>

this is edit function in the controller:

public function edit($id)
{
  $etablissement = Etablissement::find($id);

  return view('etablissements.edit', compact('etablissement'));
}

and this is update function in the controller:

    public function update(Request $request, $id)
    {
      $request->validate([
        'nom'=>'required',
        'email'=> 'required',
        'telephone' => 'required|numeric'
    ]);

    $etablissement = Etablissement::find($id);
    $etablissement->nom = $request->get('nom');
    $etablissement->email = $request->get('email');
    $etablissement->telephone = $request->get('telephone');
    $etablissement->save();

    return redirect('/etablissements')->with('success', 'Utilisateur édité');
    }
like image 523
Amine Avatar asked Jan 02 '23 05:01

Amine


1 Answers

Quote the value attribute.

<input type="text" class="form-control" name="nom" value="{{ $etablissement->nom }}" />

Without quotes, the second word in$etablissement->nom is interpreted as another attribute rather than part of the value of the value attribute.

The email and telephone values are showing up correctly because there are no spaces, but you should quote those as well just in case.

like image 127
Don't Panic Avatar answered Jan 05 '23 10:01

Don't Panic