We help IT Professionals succeed at work.
Get Started

How do I add timestamps to a table in Laravel?

Bruce Gust
Bruce Gust asked
on
74 Views
Last Modified: 2020-02-01
I migrated a table from another database into a Laravel application.

First of all, it looks like all Laravel tables include a "created_at" and an "updated_at" column that need to be added in order for any kind of update or insertion to occur without an error, yes?

I'm assuming that's the case.

So, here's what I attempted to do for a migration that added those timestamps:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AlterProfessionalTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
		Schema::table('professionals', function (Blueprint $table) {
            //
			$table->timestamps();
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
		$table->dropTimestamps();
    }
}

Open in new window



I got this error:

   Symfony\Component\Debug\Exception\FatalThrowableError  : syntax error, unexpected 'public' (T_PUBLIC), expecting ')'

  at C:\wamp64\www\new_nomas\database\migrations\2020_01_31_205053_alter_professional_table.php:27
    23|      * Reverse the migrations.
    24|      *
    25|      * @return void
    26|      */
  > 27|     public function down()
    28|     {
    29|         //
    30|                 $table->dropTimestamps();
    31|     }


Where did I blow it?
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2020
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE