Php laravel 4.2-不使用迁移的数据库
我通过运行sql查询创建了一个数据库 人员表的mysql查询如下Php laravel 4.2-不使用迁移的数据库,php,mysql,laravel,Php,Mysql,Laravel,我通过运行sql查询创建了一个数据库 人员表的mysql查询如下 use highwaymate; create table staff( staff_ID int auto_increment primary key, first_name varchar(50) not null, last_name varchar(50) not null, title enum('miss','mrs','mr','ms') not null, address varchar(50
use highwaymate;
create table staff(
staff_ID int auto_increment primary key,
first_name varchar(50) not null,
last_name varchar(50) not null,
title enum('miss','mrs','mr','ms') not null,
address varchar(500) not null,
date_of_birth date,
email varchar(50),
telephone varchar(10),
role enum('academic','non academic'),
designation_ID int,
contract_type enum('temporary','permanent'),
etf_number varchar(15),
NIC varchar(10) not null,
date_started date not null,
resigned_date date,
timestamp datetime default now(),
constraint fk_staff foreign key(designation_ID) references designations(designation_ID) on update cascade
);
我的员工模式如下
<?php
class Staff extends Eloquent
{
protected $table = 'staff';
protected $primaryKey='staff_ID';
protected $timepstamps=false;
public $incrementing=false;
}
Route::group(array('before'=>'csrf'),function(){
Route::post('/category/index/staff/new',array('uses'=>'CategoryController@postStaffAdd', 'as' => 'category-postStaffAdd'));
});
<?php
class CategoryController extends BaseController {
public function index(){
return View::make('categories.index');
}
public function staffIndex()
{
$staff = Staff::all();
return View::make('categories.staffpage')->with('staff',$staff);
}
public function staffAdd(){
return View::make('categories.staffadd');
}
public function postStaffAdd(){
$staff = new Staff;
$staff->first_name = 'John';
$staff->last_name = 'Dalton';
$staff->title = 'mr';
$staff->address = 'Panagoda, Hoamgama';
$staff->date_of_birth = '1990-12-21';
$staff->email = 'johnnydalton@gmail.com';
$staff->telephone = '0775698521';
$staff->role = 'academic';
$staff->designation_ID = 3;
$staff->contract_type = 'permanent';
$staff->etf_number = 'pending';
$staff->NIC = '901254586V';
$staff->date_started = '2015-05-02';
$staff->save();
return "You have entered a new staff member successfully";
}
}
我的员工总监如下
<?php
class Staff extends Eloquent
{
protected $table = 'staff';
protected $primaryKey='staff_ID';
protected $timepstamps=false;
public $incrementing=false;
}
Route::group(array('before'=>'csrf'),function(){
Route::post('/category/index/staff/new',array('uses'=>'CategoryController@postStaffAdd', 'as' => 'category-postStaffAdd'));
});
<?php
class CategoryController extends BaseController {
public function index(){
return View::make('categories.index');
}
public function staffIndex()
{
$staff = Staff::all();
return View::make('categories.staffpage')->with('staff',$staff);
}
public function staffAdd(){
return View::make('categories.staffadd');
}
public function postStaffAdd(){
$staff = new Staff;
$staff->first_name = 'John';
$staff->last_name = 'Dalton';
$staff->title = 'mr';
$staff->address = 'Panagoda, Hoamgama';
$staff->date_of_birth = '1990-12-21';
$staff->email = 'johnnydalton@gmail.com';
$staff->telephone = '0775698521';
$staff->role = 'academic';
$staff->designation_ID = 3;
$staff->contract_type = 'permanent';
$staff->etf_number = 'pending';
$staff->NIC = '901254586V';
$staff->date_started = '2015-05-02';
$staff->save();
return "You have entered a new staff member successfully";
}
}
我觉得,;数据类型中存在一个问题,因为当我看到参数时,诸如first\u name
之类的字符串字段似乎不是字符串。这是个问题吗
帮我解决我的问题
提前感谢。您拼错了用于禁用
Staff
模型中时间戳的属性名称,并且该属性必须是公共的
不受保护的
,因此:
protected $timepstamps = false;
// ^
// There's an extra "p" in the property name
应该是:
public $timestamps = false;
如.所示,由于您没有使用迁移,因此您的表没有由laravel添加的默认时间戳(即在列中创建和更新) 有两种方法可以解决这个问题:
- 将列添加到表中(最好通过a)
- 或者告诉你的模型你不会使用时间戳,就像这样
protected$timestamps=false代码>*请注意,我的项目中没有使用迁移。什么不起作用?你有错误吗?如果您没有提供足够的信息,我们将无法帮助您。我的问题是postStaffAdd()方法,它不起作用。它给出了一个错误,表示出现了错误检查app/storage/logs/laravel.log
中的错误日志,并编辑您的问题以包括您遇到的错误。Nimmi,更改受保护的$timepsamp='false';公开$timestamps=false;在你的员工模型中。然后请解释新的问题是什么。修复时间戳问题后出现了什么错误?Illumb\Database\QueryException请发布整个错误。这是为错误触发的唯一异常类。Illumb\Database\QueryException(42S22)HELP SQLSTATE[42S22]:未找到列:字段列表中的1054未知列“updated_at”(SQL:insert-instaff
(姓名
,姓氏
,标题
,地址
,出生日期
,电子邮件
,电话
,角色
,指定ID
,合同类型
,etf编号
,NIC
,开始日期
,,代码>创建日期
_在
)值(尼米,拉希尼卡,ms,610/68 homagama,1993-09-20,nimmirashinika@gmail.com,0713334413,非学术性,3,临时性,待定,9312534502v,2016-01-012016-02-05 10:12:492016-02-05 10:12:49)您的属性名称仍然拼写错误。我已更新我的答案以指出这一点,并提供其他信息。thnks shempignon:-)