Using variable column values in a Eloquent model
Laravel1 / 3Level:
If you ever want
/**
* The attributes that should be casted.
*
* @var array
*/
public $casts = [
'payload' => 'json',
];
/**
* Convert the model instance to an array.
*
* @return array
*/
public function toArray()
{
// this allow the payload to act as column values
return $this->payload + parent::toArray();
}
Warning: don't switch this
Good luck and hope to see you around! ✌🏻