I want to store current date time in MySQL using following laravel function. Actually, I stored static date instead of this i want store current date time at created_at
,updated_at
field in database.
function insert(Request $req)
{
$name=$req->input('name');
$address=$req->input('address');
$data=array("name" => $name,"address" => $address,"created_at"=>'2017-04-27 10:29:59',"updated_at"=>'2017-04-27 10:29:59');
DB::table('student')->insert($data);
echo "Record inserted successfully.<br/>";
return redirect('/');
}
use laravel helper function
now()
other wise used carbon
class
Carbon\Carbon::now()
used like that
$data = array("name" => $name,"address" => $address,"created_at"=> Carbon::now(),"updated_at"=> now());
DB::table('student')->insert($data);
for more information see