How to update data from an Laravel 5.2 registration?

Asked

Viewed 446 times

-1

I’m touching the Laravel a short time, I have name, email and password and wanted to know how to update this data with a form.

<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div class="panel panel-default">
                <div class="panel-heading"><h4>{{ Auth::user()->name }}</h4> </div>

                <div class="panel-body">
                    <form>
                      <div class="form-group">
                        <label for="exampleInputPassword1">Editar Nome</label>
                         <input id="name" type="text" class="form-control" name="name" value="">
                      </div>
                      <div class="form-group">
                        <label for="exampleInputEmail1">Novo E-mail</label>
                        <input id="email" type="email" class="form-control" name="email" value="">
                      </div>
                      <div class="form-group">
                        <label for="exampleInputPassword1">Nova Senha</label>
                        <input id="password" type="password" class="form-control" name="password">
                      </div>                     
                      <button type="submit" class="btn btn-default">Atualizar dados</button>
                       <a href="{{ url('/home') }}"><button type="button" class="btn btn-primary">Voltar</button></a>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


use App\Http\Requests;

class ProfileController extends Controller
{
    public function editar()
    {
        return view('editar');
    }
}

i can register a user, log in, but I’m in doubt on how to do this part of updating the person’s data.

1 answer

0

    public function update($id)
{
    $profile = Profile::find($id);
    $profile->update(Input::all());
    return view('suaView');
}

Remembering to have the $fillable fields registered in the model for Mass Assignment to work properly and safely.

You should also add the appropriate route, for example:

Route::post('profile/{id}', 'ProfilesController@update');

I hope I’ve helped.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.