Skip to content

Instantly share code, notes, and snippets.

@4lun
Created September 23, 2015 12:06
Show Gist options
  • Save 4lun/e2868654458f980cc168 to your computer and use it in GitHub Desktop.
Save 4lun/e2868654458f980cc168 to your computer and use it in GitHub Desktop.
Laravel 5.1 Base Model - adds defaults to $casts property on __construct
<?php
namespace App;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent
{
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
$this->casts = array_merge([
'id' => 'integer',
'user_id' => 'integer',
], $this->casts);
parent::__construct($attributes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment