2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models\Common;
|
|
|
|
|
|
|
|
use App\Abstracts\Model;
|
2020-01-26 02:21:34 +03:00
|
|
|
use Bkwld\Cloner\Cloneable;
|
2021-03-30 00:12:51 +03:00
|
|
|
use Illuminate\Support\Str;
|
2019-11-16 10:21:14 +03:00
|
|
|
|
|
|
|
class Report extends Model
|
|
|
|
{
|
2020-01-26 02:21:34 +03:00
|
|
|
use Cloneable;
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
protected $table = 'reports';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attributes that should be mass-assignable.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
2021-09-07 10:33:34 +03:00
|
|
|
protected $fillable = ['company_id', 'class', 'name', 'description', 'settings', 'created_from', 'created_by'];
|
2020-01-16 15:39:37 +03:00
|
|
|
|
|
|
|
/**
|
2020-11-13 15:15:27 +03:00
|
|
|
* The attributes that should be cast.
|
2020-01-16 15:39:37 +03:00
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
2023-03-16 16:36:13 +03:00
|
|
|
'settings' => 'object',
|
|
|
|
'deleted_at' => 'datetime',
|
2020-01-16 15:39:37 +03:00
|
|
|
];
|
2021-03-30 00:12:51 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Scope to only include reports of a given alias.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
|
|
|
* @param string $alias
|
|
|
|
* @return \Illuminate\Database\Eloquent\Builder
|
|
|
|
*/
|
|
|
|
public function scopeAlias($query, $alias)
|
|
|
|
{
|
|
|
|
$class = ($alias == 'core') ? 'App\\\\' : 'Modules\\\\' . Str::studly($alias) . '\\\\';
|
|
|
|
|
|
|
|
return $query->where('class', 'like', $class . '%');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the alias based on class.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getAliasAttribute()
|
|
|
|
{
|
|
|
|
if (Str::startsWith($this->class, 'App\\')) {
|
|
|
|
return 'core';
|
|
|
|
}
|
|
|
|
|
|
|
|
$arr = explode('\\', $this->class);
|
|
|
|
|
|
|
|
return Str::kebab($arr[1]);
|
|
|
|
}
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|