dimanche 17 avril 2016

Updated_at Timestamp with Laravel 4.2 DB Class

I've completed an assignment using Laravel 4.2 (as per criteria), however I missed the part about being required to use the DB class. I wrote everything in Eloquent and had it working perfectly.

I'm trying to implement the 'Updated_at' field for a table row but can't seem to figure it out. I'm sure it's simple but most sites I see just tell me to use Eloquent... Which I can't.

Table creation

CREATE TABLE posts
(
    id INTEGER PRIMARY KEY,
    title VARCHAR(255) NOT NULL,
    message VARCHAR(50000) NOT NULL,
    author VARCHAR(255) NOT NULL,
    avatar VARCHAR(255),
    created_at DATETIME DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'LOCALTIME')),
    updated_at DATETIME DEFAULT (DATETIME(CURRENT_TIMESTAMP, 'LOCALTIME'))
);

Update row

    $post = DB::update('UPDATE posts SET title=?,message=?,author=?,updated_at=? WHERE id=?',
        array(
            Input::get('title'),
            Input::get('message'),
            Input::get('author'),
            DB::raw('CURRENT_TIMESTAMP'), <-- Throwing error, what do I put here???
            $id
        )
    );

Aucun commentaire:

Enregistrer un commentaire