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

Laravel 4 has a dateTime() function that helps in creating these columns. But in Schema\Table in Laravel 3, I only see the date() function, which:

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

It looks like it just creates a DATE column. However, I also see that there is 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 can I do it? Could not find this information in the documentation.

+4
source share
1 answer

: \

It turns out macros are a recently added (very cool) feature, but that would not help me. To add a new column, you would actually need to change the Schema\Table class, and then add the new method to the MySQL grammars file for the table columns. Macros help you perform several actions simultaneously using existing table methods.

Oddly enough, as soon as I went there, it actually turns out that Laravel really already does DATETIME columns when you ask for ->date() , and not just a simple DATE column as I thought.

Assumptions: tut, tut.

+3
source

Source: https://habr.com/ru/post/1479849/


All Articles