php - Laravel 帐户详细信息更新

标签 php laravel

我仍在掌握 Laravel 框架,但一些本应简单的事情对我来说却是一个麻烦的问题。

我在 account/update.blade.php 中创建了一个 View

<form action="{{ URL::route('account-update-post') }}" method="post">
<p><input type="text" name="twitter" placeholder="Twitter handle" />
</p>
<p><input type="text" name="facebook" placeholder="Facebook handle" /> 
<p><input type="text" name="website" placeholder="Website url" /> 
<p><input type="text" name="about" placeholder="About me" /> 
<p><a href="{{ URL::route('account-change-password') }}">Change password</a></p>
<button class="button-default ">Update</button></p>
</form>

我在AccountController.php

public function postUpdate(){
        $user           = User::find(Auth::user()->id);

        $twitter    = Input::get('twitter');
        $facebook       = Input::get('facebook');

    return Redirect::route('account-update')
                ->with('global', 'Your account details could not be changed.');
}

我创建了一条路线:

/* Account update (POST) */
Route::post('/account/update', array(
    'as' => 'account-update-post',
    'uses' => 'AccountController@postUpdate'
));

在我的模型文件中,我有 Update.php

<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    protected $fillable = array('twitter', 'facebook', 'website', 'about';

    use UserTrait, RemindableTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

并使用相关字段设置我的数据库以接受此信息。我不需要对字段进行任何验证,但苦苦思索为什么它没有更新到数据库中..

最佳答案

Updating A Retrieved Model

要更新模型,您可以检索它、更改属性并使用保存方法:

$user = User::find(Auth::id());
$user->twitter = Input::get('twitter');
$user->facebook = Input::get('facebook');
$user->save();

然后添加您的路由以重定向到某个页面。看看是否有效。您可以访问Insert - Update - Delete Section来自 Laravel 文档

关于php - Laravel 帐户详细信息更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28265343/

相关文章:

php - php中的权限分配

php - wordpress 中的子主题目录

php - 当通过 Controller 路由子 URL 时,Laravel 5.2 balde/css 停止工作

php - 如何将付款存储到数据库中的多个表

javascript - jQuery 如何将唯一 ID 添加到动态表单输入字段

laravel - laravel 的路由是否足以抵御文件遍历攻击?

PHP AJAX JQUERY 加载页面

php - 在 Symfony2 中创建移动应用程序

php - mysql 没有返回所有行

mysql - 将 Laravel 查询生成器方法 whereIn() 与子查询一起使用