added source feature
This commit is contained in:
@@ -58,6 +58,8 @@ abstract class Module extends Command
|
||||
'module_id' => $this->model->id,
|
||||
'version' => $this->module->get('version'),
|
||||
'description' => trans('modules.' . $action, ['module' => $this->alias]),
|
||||
'created_from' => source_name(),
|
||||
'created_by' => user_id(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ abstract class Import implements HasLocalePreference, ShouldQueue, SkipsEmptyRow
|
||||
{
|
||||
$row['company_id'] = company_id();
|
||||
$row['created_by'] = $this->user->id;
|
||||
$row['created_from'] = 'import';
|
||||
|
||||
// Make enabled field integer
|
||||
if (isset($row['enabled'])) {
|
||||
|
||||
@@ -4,18 +4,20 @@ namespace App\Abstracts;
|
||||
|
||||
use App\Abstracts\Http\FormRequest;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\HasSource;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
use App\Interfaces\Job\ShouldDelete;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Traits\Jobs;
|
||||
use App\Traits\Relationships;
|
||||
use App\Traits\Sources;
|
||||
use App\Traits\Uploads;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
abstract class Job
|
||||
{
|
||||
use Jobs, Relationships, Uploads;
|
||||
use Jobs, Relationships, Sources, Uploads;
|
||||
|
||||
protected $model;
|
||||
|
||||
@@ -49,6 +51,10 @@ abstract class Job
|
||||
if ($this instanceof HasOwner) {
|
||||
$this->setOwner();
|
||||
}
|
||||
|
||||
if ($this instanceof HasSource) {
|
||||
$this->setSource();
|
||||
}
|
||||
}
|
||||
|
||||
public function bootUpdate(...$arguments): void
|
||||
@@ -106,4 +112,17 @@ abstract class Job
|
||||
|
||||
$this->request->merge(['created_by' => user_id()]);
|
||||
}
|
||||
|
||||
public function setSource(): void
|
||||
{
|
||||
if (! $this->request instanceof Request) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->request->has('created_from')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->request->merge(['created_from' => $this->getSourceName($this->request)]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Abstracts;
|
||||
|
||||
use App\Traits\DateTime;
|
||||
use App\Traits\Owners;
|
||||
use App\Traits\Sources;
|
||||
use App\Traits\Tenants;
|
||||
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
@@ -14,7 +15,7 @@ use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
abstract class Model extends Eloquent implements Ownable
|
||||
{
|
||||
use Cachable, DateTime, Owners, SearchString, SoftDeletes, Sortable, Tenants;
|
||||
use Cachable, DateTime, Owners, SearchString, SoftDeletes, Sortable, Sources, Tenants;
|
||||
|
||||
protected $tenantable = true;
|
||||
|
||||
@@ -211,6 +212,11 @@ abstract class Model extends Eloquent implements Ownable
|
||||
return $query->whereIn($this->table . '.contact_id', (array) $contacts);
|
||||
}
|
||||
|
||||
public function scopeSource($query, $source)
|
||||
{
|
||||
return $query->where($this->table . '.created_from', $source);
|
||||
}
|
||||
|
||||
public function scopeIsOwner($query)
|
||||
{
|
||||
return $query->where($this->table . '.created_by', user_id());
|
||||
|
||||
Reference in New Issue
Block a user