【问题标题】:Laravel edit formLaravel 编辑表单
【发布时间】:2013-11-22 09:11:21
【问题描述】:

只是想知道将详细信息保存到数据库后如何编辑它们?

我想从浏览器中编辑姓名和联系方式吗?

到目前为止,我有要编辑的占位符或内容。

<ul class="no-bullet">
    <li>Full Name: {{ $providerName }} {{ $providerSurname }}</li>
    <li>Email Adress: {{ $providerEmail }}</li>
    <li>Contact Number:</li>
    <li>Company:</li>
</ul>
<a href="#" class="small radius button">Edit Details</a>

【问题讨论】:

  • 这可能是我在 Stack Overflow 上看到的最像 Geordie 的问题。

标签: php forms frameworks laravel


【解决方案1】:

您可以将数据库模型绑定到您的表单:

Form::model($provider, array('route' => array('provider.update', $user->id)))

Laravel 会自动使用数据库数据填充您的输入。

这可能是您的accountEdit 视图:

<html>
    <head>
        <title></title>
    </head>
    <body>
        {{ Form::model($provider, array('route' => array('provider.update', $provider->id))) }}
            {{ Form::label('providerName', 'Full Name:')) }}
            {{ Form::text('providerName') }}
            {{ Form::text('providerSurname') }}

            {{ Form::label('providerEmail', 'E-Mail Address') }}
            {{ Form::text('providerEmail') }}

            {{ Form::submit('Send this form!') }}
        {{ Form::close() }}
    </body>
</html>

这可能是你的路线

Route::get('edit', function() { 
    $provider = Provider::find(1); 

    return View::make('accountEdit')->with(compact('provider'));
});   

Route::get('provider/update', array('as'=>'provider.update', function() { 

    dd(Input::all())

});         

【讨论】:

  • 我应该为 html 表单位创建一个新文件?对不起,我只是使用路由文件而不是控制器。此外,我将模型中的用户文件更改为提供者,因为我将我的“用户”称为“提供者”。 Route::get('edit', function() { $providerID = Provider::find(1); return View::make('accountEdit')->with(compact('providerID'));; });
  • 已编辑以提供更多线索并支持您的模型和路线。
  • 我收到此错误,但无法为命名路由“provider.update”生成 URL
  • 您需要在表单中使用的 POST 路由。已编辑。
【解决方案2】:
{{ Form::model($provider, array('route' => array('provider.update', $provider->id))) }}

使用上面的代码不会自动填充我的编辑表单中的字段。但是,当我像这样删除第一个数组时,表单中已经填充了数据。

{{ Form::model($provider, array('provider.update', $provider->id)) }}

【讨论】:

    猜你喜欢
    • 2016-03-27
    • 1970-01-01
    • 2019-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    相关资源
    最近更新 更多