我刚刚开始使用Laravel,我收到以下错误:
未知列'updated_at'插入gebruikers(naam,wachtwoord,updated_at,created_at)
我知道错误来自迁移表时的时间戳列,但我没有使用该updated_at字段.我曾经使用它,当我按照Laravel教程,但现在我正在制作(或试图制作)我自己的东西.即使我不使用时间戳,我也会收到此错误.我似乎无法找到它被使用的地方.这是代码:
调节器
public function created()
{
if (!User::isValidRegister(Input::all())) {
return Redirect::back()->withInput()->withErrors(User::$errors);
}
// Register the new user or whatever.
$user = new User;
$user->naam = Input::get('naam');
$user->wachtwoord = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('/users');
}
Run Code Online (Sandbox Code Playgroud)
路线
Route::get('created', 'UserController@created');
Run Code Online (Sandbox Code Playgroud)
模型
public static $rules_register = [
'naam' => 'unique:gebruikers,naam'
];
public static $errors;
protected $table = 'gebruikers';
public static function isValidRegister($data)
{
$validation = Validator::make($data, static::$rules_register);
if ($validation->passes()) {
return true;
}
static::$errors = $validation->messages();
return false;
}
Run Code Online (Sandbox Code Playgroud)
我一定是忘记了什么......我在这里做错了什么?
任何人都可以帮助我以下数据插入代码的问题是什么?
SQLSTATE [42S22]:找不到列:1054'字段列表'中的未知列'标题'(SQL:插入gallery_categories(title,description,category_id,image,updated_at,created_at)值(测试标题,测试详细信息,1,1512370315 .jpg,2017-12-04 06:51:55,2017-12-04 06:51:55))
我有两个型号.GalleryModel和GalleryCategoryModel中的一个.当我使用dd($request->all());它然后它调试完美.
NB:我是laravel的新人.
GalleryModel模型
class GalleryModel extends Model
{
protected $table = 'galleries';
protected $primaryKey = 'id';
protected $fillable = ['title', 'description', 'image', 'category_id'];
}
Run Code Online (Sandbox Code Playgroud)
这是我的GalleryCategoryModel模型
class GalleryCategoryModel extends Model
{
protected $table = 'gallery_categories';
protected $primaryKey = 'id';
protected $fillable = ['name'];
}
Run Code Online (Sandbox Code Playgroud)
我的控制器GalleriesController
public function create()
{
$categories = GalleryCategoryModel::all();
return view('pages.backend.galleries.create')->withCategories($categories);
}
public function store(StoreGalleryRequest $request)
{
$gallery = new GalleryCategoryModel;
$gallery->title = $request->title;
$gallery->description = $request->description;
$gallery->category_id = $request->category_id; …Run Code Online (Sandbox Code Playgroud)