Populate form with Auth::user()

489 views Asked by At

I'm trying to populate a form with my logged in user so I can edit some profile information.

I currently have this code (only trying to display the email first, will populate the form later once this works):

I made an editprofile.blade.php template with:

@extends('masterpage')

@section('content')

<h1> Edit Profile </h1>


{{ Form::model($user) }}

    <div class="form-group">
        {{ Form::label('email', 'E-mail') }}
        {{ Form::Text('email', null, ['class' => 'form-control']) }}
    </div>
{{ Form::close() }}

@stop

In myProfileController.php I have:

<?php namespace App\Http\Controllers;

use Auth; 
use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Html\FormFacade;
use Illuminate\Html\HtmlFacade;

class ProfileController extends Controller {

    public function show() {
        $user = Auth::user();

        return view('pages.editprofile')->withUser($user);
    }

}

In my route I added:

Route::get('/profile/edit', 'ProfileController@show');

But when I try to load the page I get this: enter image description here

I have two questions:

1: Why isn't there a form showing up with the data? As you can see the email is being loaded into the form but it displays it as text.

2. Once the data is loaded into a succesful form and the user has edited some of the data, how would I make update function to save the edited data?

1

There are 1 answers

2
lonerunner On BEST ANSWER

I think that you are just outputting the raw data because probably you are using double brackets {{ }}.

As i remember i had a same thing when i migrated a site from laravel 4 to laravel 5. They changed the way blade output and echo the data. try to change double brackets {{ }} to this {{!! !!}} or this {{{ }}} i don't remember exactly which one it is.

Edit: about saving you can use controllers so when user post the data it goes to something like the same url just with post method, so it calls the update function inside controller.

For some functions where user should have full control over his profile like edit, update, delete, create i would use the examples from this http://laravel.com/docs/5.0/controllers#restful-resource-controllers take a look at restful controller