added ownership
This commit is contained in:
@ -9,25 +9,25 @@ use App\Events\Common\CompanyMakingCurrent;
|
||||
use App\Models\Document\Document;
|
||||
use App\Traits\Contacts;
|
||||
use App\Traits\Media;
|
||||
use App\Traits\Owners;
|
||||
use App\Traits\Tenants;
|
||||
use App\Traits\Transactions;
|
||||
use App\Utilities\Overrider;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Kyslik\ColumnSortable\Sortable;
|
||||
use Laratrust\Contracts\Ownable;
|
||||
use Lorisleiva\LaravelSearchString\Concerns\SearchString;
|
||||
|
||||
class Company extends Eloquent
|
||||
class Company extends Eloquent implements Ownable
|
||||
{
|
||||
use Contacts, Media, SearchString, SoftDeletes, Sortable, Tenants, Transactions;
|
||||
use Contacts, Media, Owners, SearchString, SoftDeletes, Sortable, Tenants, Transactions;
|
||||
|
||||
protected $table = 'companies';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
protected $dates = ['deleted_at'];
|
||||
|
||||
protected $fillable = ['domain', 'enabled'];
|
||||
protected $fillable = ['domain', 'enabled', 'created_by'];
|
||||
|
||||
protected $casts = [
|
||||
'enabled' => 'boolean',
|
||||
@ -518,4 +518,23 @@ class Company extends Eloquent
|
||||
{
|
||||
return static::getCurrent() !== null;
|
||||
}
|
||||
|
||||
public function scopeIsOwner($query)
|
||||
{
|
||||
return $query->where('created_by', user_id());
|
||||
}
|
||||
|
||||
public function scopeIsNotOwner($query)
|
||||
{
|
||||
return $query->where('created_by', '<>', user_id());
|
||||
}
|
||||
|
||||
public function ownerKey($owner)
|
||||
{
|
||||
if ($this->isNotOwnable()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $this->created_by;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,21 @@ class Contact extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'type', 'name', 'email', 'user_id', 'tax_number', 'phone', 'address', 'website', 'currency_code', 'reference', 'enabled'];
|
||||
protected $fillable = [
|
||||
'company_id',
|
||||
'type',
|
||||
'name',
|
||||
'email',
|
||||
'user_id',
|
||||
'tax_number',
|
||||
'phone',
|
||||
'address',
|
||||
'website',
|
||||
'currency_code',
|
||||
'reference',
|
||||
'enabled',
|
||||
'created_by',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
|
@ -18,7 +18,7 @@ class Dashboard extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'enabled'];
|
||||
protected $fillable = ['company_id', 'name', 'enabled', 'created_by'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
|
@ -27,7 +27,7 @@ class Item extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'description', 'sale_price', 'purchase_price', 'category_id', 'enabled'];
|
||||
protected $fillable = ['company_id', 'name', 'description', 'sale_price', 'purchase_price', 'category_id', 'enabled', 'created_by'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
|
@ -18,7 +18,6 @@ class Recurring extends Model
|
||||
*/
|
||||
protected $fillable = ['company_id', 'recurable_id', 'recurable_type', 'frequency', 'interval', 'started_at', 'count'];
|
||||
|
||||
|
||||
/**
|
||||
* Get all of the owning recurable models.
|
||||
*/
|
||||
|
@ -17,7 +17,7 @@ class Report extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'class', 'name', 'description', 'settings'];
|
||||
protected $fillable = ['company_id', 'class', 'name', 'description', 'settings', 'created_by'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
|
@ -16,7 +16,7 @@ class Widget extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'dashboard_id', 'class', 'name', 'sort', 'settings'];
|
||||
protected $fillable = ['company_id', 'dashboard_id', 'class', 'name', 'sort', 'settings', 'created_by'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
|
Reference in New Issue
Block a user