-
Notifications
You must be signed in to change notification settings - Fork 246
Expand file tree
/
Copy pathProcessMakerModel.php
More file actions
57 lines (47 loc) · 1.41 KB
/
ProcessMakerModel.php
File metadata and controls
57 lines (47 loc) · 1.41 KB
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
49
50
51
52
53
54
55
56
57
<?php
namespace ProcessMaker\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Cache;
/**
* Base class that all models should extend from.
*/
class ProcessMakerModel extends Model
{
use HasFactory;
const MIGRATION_COLUMNS_CACHE_KEY = 'migration_columns';
/**
* Prepare a date for array / JSON serialization.
*
* @param DateTimeInterface $date
* @return string
*/
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
public function scopeExclude($query, array $columns)
{
if (empty($columns)) {
return $query;
}
$columnsToShow = array_diff($this->getTableColumns(), $columns);
$columnsToShow = array_map(function ($column) {
return $this->table . '.' . $column;
}, $columnsToShow);
return $query->select($columnsToShow);
}
private function getTableColumns()
{
$key = 'MigrMod:' . $this->getTable();
return Cache::tags(static::MIGRATION_COLUMNS_CACHE_KEY)->rememberForever(
$key, function () {
return $this->getConnection()
->getSchemaBuilder()
->getColumnListing($this->getTable());
}
);
}
}