Laravel 4.x provide n number of services to solve basic issues. By using Laravel 4.x we will easily set a default attribute for a Laravel/Eloquent model.
To achieve this we have to define value like below example:
Example:
protected $defaults = array(
'quantity' =9,
);
public function __construct(array $attributes = array())
{
$this->setRawAttributes($this->defaults, true);
parent::__construct($attributes);
}
I will suggest this as a PR so we don't need to declare this constructor at every Model, and can easily apply by simply declaring the $defaults array in our models...
By this way we can set default default attribute value for a laravel.
0 Comment(s)