Laravel插入日期created_at从1到30

时间:2018-04-13 16:21:34

标签: php laravel-5

我尝试在自定义表格中插入数据

$month  = date('m');
$year   = date('y');
$number = cal_days_in_month(CAL_GREGORIAN, $month, $year);

for ($i = 0; $i < $number; $i++) {
    $test = new Test();
    $test->cuid = $user->id;
    $test->name = $user->name;
    $test->month = date('m');
    $test->created_at = '2018-04-'+$i;
    $test->save();
}

我尝试在一个月内插入数字记录

让我们说四月有30天我尝试插入它工作正常但在created_at字段我需要插入2018-04-01到2018-04-30但这只插入当前日期,以便我尝试上面但不工作< / p>

1 个答案:

答案 0 :(得分:0)

您需要设置timestamps = false;

function call(){ console.log(fun); $.ajax({ url: "http://localhost/mt2/checkanswer.php", dataType: "jsonp", type: "POST", //window.alert("what"); data: { num1:2, num2:2, answer:5 }, success: function( data1 ) { console.log(data1); $( "#timeDiv" ).html( "<strong>" + data1 + "</strong><br>"); } <?php // get two numbers and the answer (their product) and return true or false if the answer is correct or not. // using this as an api call, return json data // calling <your host>/checkanswer.php?num1=4&num2=5&answer=20 will return true // calling <your host>/checkanswer.php?num1=4&num2=5&answer=21 will return false if(isset($_GET['num1']) && isset($_GET['num2']) && isset($_GET['answer']) && is_numeric($_GET['num1']) && is_numeric($_GET['num2']) && is_numeric($_GET['answer'])) { $product = $_GET["num1"] * $_GET["num2"]; if ($product === intval($_GET['answer'])) { $result = true; } else { $result = false; } header('Content-type: application/json'); echo json_encode($result); } ?>