我有一个索引文件,该文件在值数组上调用create方法。 插入数据库的工作,但是,除id以外的所有列都为空。 我在这里很茫然,没有抛出任何错误。任何指导表示赞赏。
index.php
<?php
include_once 'posts.php';
$parameters = array('id' => null, 'title' => 'Title', 'body' => 'Body', 'create_date' => '2019-03-20');
$result = Post::create($parameters);
posts.php
<?php
require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
use \Illuminate\Database\Eloquent\Model;
class Post extends Model {
public $timestamps = false;
protected $fillable = ['title', 'body', 'create_date'];
public function __construct()
{
$capsule = new Capsule;
$capsule->addConnection([
"driver" => "mysql",
"host" => "localhost",
"database" => "db",
"username" => "user",
"password" => "pass",
"charset" => "utf8mb4",
"collation" => "utf8mb4_unicode_ci",
"prefix" => ""
]);
$capsule->bootEloquent();
}
}
数据库插入