framework
framework copied to clipboard
Default timestamps in mass assignment
When I try to insert a new record to table, getting an error. It says: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list'
Maybe it is about the design of the framework. How can I make the model that it does not have timestamps?
models/Company.php:
<?php
class Company extends Eloquent {
protected $table = 'companies';
protected $fillable = array('name', 'detail', 'city', 'phone', 'coordinates', 'website');
public static $rules = array(
'name' => 'required|min:2',
'city' => 'required'
);
}
controllers/CompanyController.php
<?php
class CompanyController extends BaseController {
protected $layout = 'layouts.master';
public function __construct()
{
$this->beforeFilter('auth', array('only'=>array('getAdd', 'postCreate')));
}
public function getAdd()
{
$this->layout->content = View::make('company.form');
}
public function postCreate()
{
$validator = Validator::make(Input::all(), Company::$rules);
if ($validator->passes()) {
$company = new Company(Input::all());
$company->save();
return Redirect::to('company/add')->with('message', Lang::get('messages.add_success'));
}
else{
return Redirect::to('company/add')->with('message', Lang::get('messages.error_occured'))
->withErrors($validator)
->withInput();
}
}
}
class Company
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}
See http://laravel.com/docs/eloquent#timestamps