-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathNormalizableModel.php
45 lines (38 loc) · 1.12 KB
/
NormalizableModel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Stidges\LaravelDbNormalizer;
use Illuminate\Support\Contracts\ArrayableInterface;
use Illuminate\Database\Eloquent\Model;
use Stidges\LaravelDbNormalizer\Database\EloquentBuilder as Builder;
abstract class NormalizableModel extends Model
{
/**
* Create a new Eloquent query builder for the model.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Stidges\LaravelDbNormalizer\Database\EloquentBuilder|static
*/
public function newEloquentBuilder($query)
{
return new Builder($query);
}
/**
* Create a new model instance that is existing.
*
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model|static
*/
public function newFromBuilder($attributes = array())
{
$instance = $this->newInstance([], true);
if ($attributes instanceof ArrayableInterface)
{
$attributes = $attributes->toArray();
}
else
{
$attributes = (array) $attributes;
}
$instance->setRawAttributes($attributes, true);
return $instance;
}
}