prism-x /
laravel-schemaless
| 1 | <?php |
||
| 2 | |||
| 3 | namespace PrismX\Schemaless\Traits; |
||
| 4 | |||
| 5 | use Illuminate\Database\Eloquent\Model; |
||
| 6 | use PrismX\Schemaless\Support\DocumentScope; |
||
| 7 | |||
| 8 | trait HasSchemalessTable |
||
| 9 | { |
||
| 10 | public static function bootHasSchemalessTable() |
||
| 11 | { |
||
| 12 | static::saving(function (Model &$model) { |
||
| 13 | $model->model = $model->model ?: get_class($model); |
||
| 14 | $model->locale = $model->locale ?: app()->getLocale(); |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 15 | }); |
||
| 16 | |||
| 17 | // limit query of this model to its type |
||
| 18 | static::addGlobalScope(new DocumentScope()); |
||
| 19 | } |
||
| 20 | |||
| 21 | public function getTable() |
||
| 22 | { |
||
| 23 | return '_documents'; |
||
| 24 | } |
||
| 25 | |||
| 26 | public function getFillable() |
||
| 27 | { |
||
| 28 | return array_merge( |
||
| 29 | parent::getFillable(), |
||
| 30 | [ |
||
| 31 | 'model', |
||
| 32 | 'locale', |
||
| 33 | 'collection', |
||
| 34 | ] |
||
| 35 | ); |
||
| 36 | } |
||
| 37 | } |
||
| 38 |