Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 1 year ago.
0

Use DB::raw(...).

In your case:

public static create($data) {
  $data['b'] = DB::raw('now()');
  parent::create($data);
}
Last updated 1 year ago.
0

why not use date("Y-m-d H:i:s") ?

Last updated 1 year ago.
0

Worked a treat!

The reason I didn't use date("Y-m-d H:i:s") was that I wasn't really all that interested in NOW() as the actual function. I'm doing some work with PostGIS which requires a whole load of stuff like:

$this->geom_point = DB::raw('ST_SetSRID(ST_MakePoint(' . $this->longitude . ',' . $this->latitude . '), ' . $this->srid . ')');

So I was looking for the more generic solution.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

c0ntax c0ntax Joined 11 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.