troubleshooting Question

How do I add timestamps to a table in Laravel?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
LaravelPHP
4 Comments1 Solution83 ViewsLast Modified:
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();
    }
}


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?
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros