-
Notifications
You must be signed in to change notification settings - Fork 1
/
BaseModel.php
48 lines (41 loc) · 1.31 KB
/
BaseModel.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
46
47
48
<?php
namespace Ghunti\LaravelBase\Models;
use Ghunti\LaravelBase\Interfaces\ValidationRulesProviderInterface;
use Ghunti\LaravelBase\Interfaces\ModelInterface;
use Ghunti\LaravelBase\Eloquent\BaseBuilder;
use Illuminate\Database\Eloquent\Model;
abstract class BaseModel extends Model implements ValidationRulesProviderInterface, ModelInterface
{
/**
* Return validation rules for the current model.
* If model exists, then edit rules are returned, otherwise, creation rules are.
*
* @return array The validation rules array
*/
public function getValidationRules()
{
return $this->exists ? $this->getEditRules() : $this->getCreateRules();
}
/**
* Create a new Eloquent query builder for the model.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Ghunti\LaravelBase\Eloquent\BaseBuilder
*/
public function newEloquentBuilder($query)
{
return new BaseBuilder($query);
}
/**
* Return the creation rules for the current model
*
* @return array The validation rules array
*/
abstract protected function getCreateRules();
/**
* Return the edition rules for the current model
*
* @return array The validation rules array
*/
abstract protected function getEditRules();
}