class Product extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
public $timestamps = true;
protected $fillable = ['name'];
protected $connection = 'pos';
public function __construct()
{
config(['database.connections.pos.database' => 'pos_1']);
parent::__construct();
}
}
Product::create(['name' => 'Snack']);
on my db id=1, name=null, created_at='2016-06-26 18:30:24', updated_at='2016-06-26 18:30:24', deleted_at=null
Why name=null?
Update post
works when I use
$p = new Product();
$p->name = 'Snack';
$p->save();
but why Product::create(['name' => 'Snack']);
fill as null ?
Update post(solved)
ah I missing pass array as parameter on that constructor.
public function __construct(array $attributes)
{
config(['database.connections.pos.database' => 'pos_1']);
parent::__construct($attributes);
}