I have this problem that laravel eloquent seems creating entry in the database but attributes other than the 'id' are null.
Here's my entity class:
<?php
class StockEntity extends Eloquent
{
public $name;
public $symbol;
public $currency;
protected $table = 'stocks';
public $timestamps = false;
protected $guarded = array();
protected $fillable = array('name', 'symbol', 'currency');
public function __construct($sName, $sSymbol, $sCurrency)
{
$this->name = $sName;
$this->symbol = $sSymbol;
$this->currency = $sCurrency;
}
}
?>
In my code I am doing this to save the data to database
$sEnt = new StockEntity("Bank", "BDO", "USD"); //this is just made up data
$sEnt->save();
When I execute the code it is creating entry in the database but with null value columns. I cant post a screenshot but this is how the db looks like:
# id | name | symbol | currency
1 | | |
2 | | |
3 | | |
I spent hours but still can't figure it out. By the way - this is the first time I used laravel and eloquent ORM.
Thanks for your help!
fill()? And you're overriding Eloquent's constructor, stopping it from doing its job