Error 500 with save() method of eloquent/laravel
Ad
I want to save an object with Laravel's eloquent
but I get error 500 when trying to save.
This is my model code:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Categorie extends Model
{
}
and this is my action:
public function addCategorie() {
$input = Input::all();
$categorie = new Categorie;
$categorie->libelle = $input['label'];
$categorie->save();
return $categorie;
}
When I use print_r($categorie)
after the save method I get a result, but when I use the save()
method I got this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into `categories` (`libelle`, `description`, `updated_at`, `created_at`) values (sss, zzz, 2015-12-23 16:20:30, 2015-12-23 16:20:30 ))
Ad
Answer
Ad
In your migration file for categories
table, you need to have
Schema::create("categories", function($table){
// Id, name, etc
$table->timestamps();
}
so that eloquent
queries can update when this entry was created and saved, or created_at
and updated_at
. If you don't want to use these timestamps, add
class Categorie extends Model {
public $timestamps = false;
}
to your Categorie
model.
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad