Php 如何形成post(验证和更新我的数据库)-控制器语法

Php 如何形成post(验证和更新我的数据库)-控制器语法,php,laravel,laravel-5,eloquent,Php,Laravel,Laravel 5,Eloquent,我已经设法在我的配置文件视图中检索并显示了Auth用户配置文件的详细信息,但是我缺少一些(或一些)实际更新的内容 你能帮忙吗 profile.blade.view <div class="row"> <div class="col-md-10 col-md-offset-1"> <div class="panel panel-default"> <div class="panel-heading"&

我已经设法在我的配置文件视图中检索并显示了Auth用户配置文件的详细信息,但是我缺少一些(或一些)实际更新的内容

你能帮忙吗

profile.blade.view

    <div class="row">
    <div class="col-md-10 col-md-offset-1">
        <div class="panel panel-default">
            <div class="panel-heading">Update your user profile</div>

            <div class="panel-body">                    

            {!! Form::open(array('action' => array('HomeController@postProfileEdit', $user->id))) !!}

            <div class="form-group">
            {!! Form::label('firstName', 'First name:') !!}
            {!! Form::text('firstName', $userinfo->first_name, ['class' => 'form-control']) !!}

            {!! Form::label('lastName', 'Last name:') !!}
            {!! Form::text('lastName', $userinfo->last_name, ['class' => 'form-control']) !!}
            </div>

            <div class="form-group">
            {!! Form::submit('Update', ['class'=>'btn primary']) !!}
            </div>

            {!! Form::close() !!}
            </div>
        </div>
    </div>
</div>
HomeController.php-profile()

HomeController.php-postProfileEdit(请求$Request)

requests.php-用于验证

abstract class Request extends FormRequest {

/**
 * The URI to redirect to if validation fails
 *
 * @var string
 */
protected $redirect = 'users/create';

/**
 * Get the validation rules that apply to the request.
 *
 * @return array
 */
public function rules()
{
    return [
        'firstName' => 'required|min:3',
        'lastName' => 'required|min:3'
    ];
}

/**
 * Determine if the user is authorized to make this request.
 *
 * @return bool
 */
public function authorize()
{
    return false;
}

}
我得到:

HomeController.php第170行中的FatalErrorException:未找到类“App\Http\Controllers\updateProfile”

我知道$updateProfile=newupdateprofile

线路错了,我只是不知道怎么了

希望这是有意义的


更新:

我在HomeController.php中将类从updateProfile更改为User(进行更改的模型的名称)

现在我得到以下信息:

HomeController.php第174行中的ErrorException:未定义变量:userinfo

我不确定是否可以使用profile.blade.view中的userinfo(见上文)


更新

我能够通过修复使它工作(或者不出错) HomeController@postProfileEdit(发布),然后返回到HomeController@profile当完成时。但是显然,保存没有完成,因为即使我更改了first_name值,当我返回到HomeController@profile(检索并显示第一个_名称)

此错误意味着Laravel正在当前App\Http\Controllers命名空间中查找updateProfile类,但找不到它。我猜该类位于不同的命名空间中,因此您需要在HomeController文件的开头添加use语句,例如:

<?php

namespace App\Http\Controllers;

use Some\Namespace\updateProfile;

基于@jedrzej.kurylo的答案

我必须假设
updateProfile
app
目录中的一个有说服力的模型:

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class updateProfile extends Model {
    ...
}
默认情况下,在Laravel中构造类时,它会查找您正在使用的控制器的当前命名空间。在本例中,它试图在
App\Http\Controllers
命名空间中找到一个类
updateProfile
,我们知道它不存在

有两种方法可以完成你想做的事情。首先,在控制器顶部为每个
模型使用
use
语句

use App\updateProfile;
...
其次,在声明类时指定命名空间:

$updateProfile = new \App\updateProfile;

任何一种方法都应该为您清除错误。

它是否显示任何错误?路径是否正确?@DaniloKobold是的,抱歉,我在HomeController.php第170行中发现:FatalErrorException:未找到类“App\Http\Controllers\updateProfile”。我知道$updateProfile=newupdateprofile;线路错了,我只是不知道怎么了。谢谢我不好意思说我想出了updateProfile这个名字,它在任何地方都没有定义。我将其更改为User,因为这是我正在更新的表(用户)的模型名称。您发现了我的问题,updateProfile只是我选择的一个随机名称,我意识到它没有意义。正如你所见,我不知道我在做什么。我正在尝试更新用户表(用户模型),因此相应地对其进行了更改。现在我不知道如何将表单数据从视图传递到控制器。
<?php

namespace App\Http\Controllers;

use Some\Namespace\updateProfile;
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class updateProfile extends Model {
    ...
}
namespace App\Http\Controllers;
use App\updateProfile;
...
$updateProfile = new \App\updateProfile;