phplaravellaravel-3

Adding a DATETIME column via a migration? Should I use macros?


In Laravel 4 there's a dateTime() function that helps in creating these columns. But in Schema\Table in Laravel 3, I only see a date() function, which is:

public function date($name)
{
    return $this->column(__FUNCTION__, compact('name'));
}

Looks like it just creates a DATE column. However, I also see that there's this magic function:

public function __call($method, $parameters)
{
    if (isset(static::$macros[$method]))
    {
        array_unshift($parameters, $this);
        return call_user_func_array(static::$macros[$method], $parameters);
    }

    throw new \Exception("Method [$method] does not exist.");
}

Is there a way to create a DATETIME column using this function? How do I go about it? Could not find this info in the documentation.


Solution

  • :\

    Turns out Macros is a recently added (very cool) feature, but this wouldn't have helped me. In order to add a new column, one would actually have to modify the Schema\Table class, and then add a new method in the MySQL grammars file for table columns. Macros only helps with doing multiple things with the existing table methods at once.

    Funnily enough, once I went there, it actually turns out that Laravel indeed already makes DATETIME columns when you ask for ->date(), not a simple DATE column like I thought.

    Assumptions: tut, tut.