How can I pass variables from a child class into the methods of a parent constructors class? I am able to create an asset with this constructor without any problems.
I have a feeling that this has something to do with the way that eloquent is handling the protected videos. All three of the variables are making it to their respective methods before the error is being thrown.
//Parent Class
class Asset extends Model
{
protected $fillable = [
'type', 'title','origin',
];
// protected $author_id;
// protected $keywords = [];
// protected $proof_status;
// protected $description;
// protected $usageHistory;
public function __construct($type, $title, $origin)
{
$this->setType($type);
$this->setTitle($title);
$this->setOrigin($origin);
}
// Setters
public function setType($type){
$this->type = $type;
}
public function setTitle($title)
{
$this->title = $title;
}
public function setOrigin($origin)
{
$this->origin = $origin;
}
public function setAltTitle($alt_title)
{
$this->alt_title = $alt_title;
}
public function setDescription($description)
{
$this->description = $description;
}
}
// Child Class
class Recipe extends Asset
{
public function __construct($type, $title, $origin){
parent::__construct($type, $title, $origin);
}
}
I expected this to set $type, $origin, and $title but instead this is the error that I receive
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'type' in 'field list' (SQL: insert into `recipes` (`type`, `updated_at`, `created_at`) values (recipe, 2019-07-11 19:35:23, 2019-07-11 19:35:23))