Home » Mysql » Laravel:Unknown column 'updated_at'

Laravel:Unknown column 'updated_at'

Posted by: admin November 1, 2017 Leave a comment

Questions:

I’ve just started with Laravel and I get this error: Unknown column 'updated_at' insert into gebruikers (naam, wachtwoord, updated_at, created_at) I know this updated_at thing is from the timestamp column when you migrate a table, but I’m not using the updated_at. I used to use it when I followed the Laravel tutorial but now that I am making(or attempting to make) my own stuff I get this error even though I dont use timestamps. I cant seem to find the place where it’s being used. This is the code:

Controller:

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');  
}

The routing:

Route::get('created', '[email protected]');

The model:

 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;
    }

I must be forgetting something… What am I doing wrong here?

Answers:

In the model, write the below code;

public $timestamps = false;

This would work.

Questions:
Answers:

For those who are using laravel 5 or above must use public modifier other wise it will throw an exception

Access level to App\yourModelName::$timestamps must be
public (as in class Illuminate\Database\Eloquent\Model)

public $timestamps = false;

Questions:
Answers:
$id = put her id;
$update['user_id'] = $userId;
Use where(array('_id'=>$id))->pull($update);