我需要使用laravel将简单的表单数据添加到数据库中
每次表单发布数据进入数据库,但我收到此错误
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tf.FirstName' in 'field list' (SQL: insert into `tbl_fundraising_pages` (`Permalink`, `Name`, `Summary`, `Story`, `Goal_Amount`, `End_Date`, `Designation`, `WebAddress`, `Block_SearchEngine`, `CharityID`, `updated_at`, `created_at`) values (Something-Like-That, Something Like That, Something Like That, <p>Something Like That</p> , 500, 11/04/2014, General Fund, Something-Like-That, NewDesig, 1387, 2014-11-21 15:14:19, 2014-11-21 15:14:19)
数据库中没有提交tf.FirstName和查询模态
<?php
class Fundraising extends Eloquent{
protected $table = 'tbl_fundraising_pages';
protected $fillable = [
'fundraiser_id',
'Permalink',
'Name',
'Summary',
'Story',
'Goal_Amount',
'End_Date',
'Designation',
'WebAddress',
'Block_SearchEngine',
'CharityID'
];
}
控制器功能
public function postCreatePage(){
$charities = Charities::where('Charity_Name','=',''.Input::get('NonprofitName').'')->first();
$data = array(
'Permalink' => str_replace(' ', '-', Input::get('FundraiserName')),
'Name' => Input::get('FundraiserName'),
'Summary' => Input::get('Summary'),
'Story' => Input::get('YourPassion'),
'Goal_Amount' => Input::get('GoalAmount'),
'Designation' => Input::get('Designation'),
'WebAddress' => str_replace(' ', '-', Input::get('FundraiserName')),
'Block_SearchEngine' => Input::get('NewDesig')
);
if(Input::get('NonprofitName')){
$data['CharityID'] = $charities->ID;
}
$page = new Fundraising();
foreach ($data as $key => $insert){
$page->$key = $insert;
}
if($page->save()){
return Response::json(array('message' => 'Done'));
}
}
我不清楚这个提交的来源?
HTML表单中没有任何内容在Ajax调用中没有任何内容
2 回答
可能在迁移的某个地方,定义了
FirstName
列,因为错误告诉我们Unknown column 'tf.FirstName'
. 由于您的控制器没有对此列做任何事情,我建议找到它并删除 .表
FirstName
列不存在于表中,但我可以看到您有一列Name
也许就是那一列 .