Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表单数据为';t提交到Laravel控制器中的数据库_Php_Laravel - Fatal编程技术网

Php 表单数据为';t提交到Laravel控制器中的数据库

Php 表单数据为';t提交到Laravel控制器中的数据库,php,laravel,Php,Laravel,在我的Laravel项目的主页中,我有一个包含表单的模式 跟我们说说你自己吧! 添加你的网站,Carrd,Youtube频道,任何东西! 提交 当然,在我的web.php文件中,我做了这样一条路线: Route::post('/profilesubmit',App\Http\Controllers\ProfilesController@profileSubmit'); 它指的是我的ProfilesController中的函数,它应该从表单中获取数据并将其保存到我的数据库中 public f

在我的Laravel项目的主页中,我有一个包含表单的模式


跟我们说说你自己吧!
添加你的网站,Carrd,Youtube频道,任何东西!
提交
当然,在我的web.php文件中,我做了这样一条路线:

Route::post('/profilesubmit',App\Http\Controllers\ProfilesController@profileSubmit');
它指的是我的ProfilesController中的函数,它应该从表单中获取数据并将其保存到我的数据库中

public function profileSubmit(请求$Request){
$user=Auth::user();
$user->bio=$request->bio;
$user->profileurl=$request->profileurl;
$user->save();
返回重定向(“主页”);
}
}
$user
变量应获取数据库中经过身份验证(登录)的用户。这一切的目的都是为了让他们可以提交一个bio和URL,最终会放在他们的个人资料中,但现在它只是放在表中的“bio”和“profileurl”列中


但是,当我提交表单时,它没有添加任何内容。值得注意的是,它说“save()”是一个未定义的方法,这很奇怪,因为当我将$user定义为“Auth::user();”时,它只是作为一个错误被捕获。有什么帮助吗?

您需要为每个

只有具有name属性的表单元素才会传递其值 提交表格时

同时为AntiCSRF添加
{{csrf_field()}}

这里我重写了你的代码

<form id="profilesubmitform" method="POST" action="/profilesubmit">
    {{ csrf_field() }}
    <div>
        <input type="textarea" id="bio" name="bio" placeholder="Enter your bio here">
        <small>Tell us about yourself!</small>
    </div>
    <div>
        <input type="text" id="profileurl" name="profileUrl" placeholder="Website/Link">
        <small>Add your site, Carrd, Youtube channel, anything!</small>
    </div>
    <button type="submit">Submit</button>
</form>

{{csrf_field()}}
跟我们说说你自己吧!
添加你的网站,Carrd,Youtube频道,任何东西!
提交

阅读有关
名称的信息
属性您可以在稍微模糊的模型中编写代码。那个属性呢..?在提交新代码后,我遇到了一个完整性约束冲突错误。我想这可能只是因为csrf,但我也加了一点。