duanhe4267 2015-06-09 19:20
浏览 57
已采纳

使用Auth :: user()填充表单

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条回答 默认 最新

  • dpowhyh70416 2015-06-09 19:36
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀