added soft delete to settings table
This commit is contained in:
parent
ea4a968f0f
commit
3249e7b18d
@ -56,11 +56,6 @@ abstract class Model extends Eloquent implements Ownable
|
||||
return parent::update($attributes, $options);
|
||||
}
|
||||
|
||||
public static function observe($classes)
|
||||
{
|
||||
parent::observe($classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Global company relation.
|
||||
*
|
||||
|
@ -12,6 +12,17 @@ class Settings extends ApiController
|
||||
{
|
||||
use Helpers;
|
||||
|
||||
/**
|
||||
* Instantiate a new controller instance.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Add CRUD permission check
|
||||
$this->middleware('permission:create-settings-settings')->only('create', 'store', 'duplicate', 'import');
|
||||
$this->middleware('permission:read-settings-settings')->only('index', 'show', 'edit', 'export');
|
||||
$this->middleware('permission:update-settings-settings')->only('update', 'enable', 'disable', 'destroy');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
|
30
app/Listeners/Update/V21/Version2133.php
Normal file
30
app/Listeners/Update/V21/Version2133.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Update\V21;
|
||||
|
||||
use App\Abstracts\Listeners\Update as Listener;
|
||||
use App\Events\Install\UpdateFinished as Event;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
|
||||
class Version2133 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '2.1.33';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($this->skipThisUpdate($event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Artisan::call('migrate', ['--force' => true]);
|
||||
}
|
||||
}
|
@ -76,7 +76,7 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
|
||||
public function companies()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Common\Company', 'user', 'user_companies', 'user_id', 'company_id');
|
||||
return $this->belongsToMany('App\Models\Common\Company', 'App\Models\Auth\UserCompany');
|
||||
}
|
||||
|
||||
public function contact()
|
||||
@ -86,7 +86,7 @@ class User extends Authenticatable implements HasLocalePreference
|
||||
|
||||
public function dashboards()
|
||||
{
|
||||
return $this->morphToMany('App\Models\Common\Dashboard', 'user', 'user_dashboards', 'user_id', 'dashboard_id');
|
||||
return $this->belongsToMany('App\Models\Common\Dashboard', 'App\Models\Auth\UserDashboard');
|
||||
}
|
||||
|
||||
/**
|
||||
|
31
app/Models/Auth/UserCompany.php
Normal file
31
app/Models/Auth/UserCompany.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
|
||||
class UserCompany extends Model
|
||||
{
|
||||
protected $table = 'user_companies';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['user_id', 'company_id'];
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User');
|
||||
}
|
||||
}
|
31
app/Models/Auth/UserDashboard.php
Normal file
31
app/Models/Auth/UserDashboard.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Auth;
|
||||
|
||||
use App\Abstracts\Model;
|
||||
|
||||
class UserDashboard extends Model
|
||||
{
|
||||
protected $table = 'user_dashboards';
|
||||
|
||||
protected $tenantable = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['user_id', 'company_id'];
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User');
|
||||
}
|
||||
}
|
@ -267,7 +267,7 @@ class Company extends Eloquent implements Ownable
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->morphedByMany('App\Models\Auth\User', 'user', 'user_companies', 'company_id', 'user_id');
|
||||
return $this->belongsToMany('App\Models\Auth\User', 'App\Models\Auth\UserCompany');
|
||||
}
|
||||
|
||||
public function vendors()
|
||||
|
@ -38,7 +38,7 @@ class Dashboard extends Model
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->morphedByMany('App\Models\Auth\User', 'user', 'user_dashboards', 'dashboard_id', 'user_id');
|
||||
return $this->belongsToMany('App\Models\Auth\User', 'App\Models\Auth\UserDashboard');
|
||||
}
|
||||
|
||||
public function widgets()
|
||||
|
@ -18,7 +18,7 @@ class Category extends Model
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled', 'created_from', 'created_by',];
|
||||
protected $fillable = ['company_id', 'name', 'type', 'color', 'enabled', 'created_from', 'created_by'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
|
@ -2,13 +2,10 @@
|
||||
|
||||
namespace App\Models\Setting;
|
||||
|
||||
use App\Traits\Tenants;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use App\Abstracts\Model;
|
||||
|
||||
class Setting extends Eloquent
|
||||
class Setting extends Model
|
||||
{
|
||||
use Tenants;
|
||||
|
||||
protected $table = 'settings';
|
||||
|
||||
/**
|
||||
@ -18,42 +15,13 @@ class Setting extends Eloquent
|
||||
*/
|
||||
protected $fillable = ['company_id', 'key', 'value'];
|
||||
|
||||
public $allAttributes = [];
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* Create a new Eloquent model instance.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
$this->allAttributes = $attributes;
|
||||
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the model in the database.
|
||||
*
|
||||
* @param array $attributes
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function update(array $attributes = [], array $options = [])
|
||||
{
|
||||
$this->allAttributes = $attributes;
|
||||
|
||||
return parent::update($attributes, $options);
|
||||
}
|
||||
|
||||
public function company()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Company');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include by prefix.
|
||||
*
|
||||
@ -66,17 +34,4 @@ class Setting extends Eloquent
|
||||
{
|
||||
return $query->where('key', 'like', $prefix . '.%');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to only include company data.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $company_id
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function scopeCompanyId($query, $company_id)
|
||||
{
|
||||
return $query->where($this->qualifyColumn('company_id'), '=', $company_id);
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ class Event extends Provider
|
||||
'App\Listeners\Update\V21\Version2125',
|
||||
'App\Listeners\Update\V21\Version2126',
|
||||
'App\Listeners\Update\V21\Version2127',
|
||||
'App\Listeners\Update\V21\Version2133',
|
||||
],
|
||||
'Illuminate\Auth\Events\Login' => [
|
||||
'App\Listeners\Auth\Login',
|
||||
|
48
database/migrations/2022_03_02_000000_core_v2133.php
Normal file
48
database/migrations/2022_03_02_000000_core_v2133.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('settings', function (Blueprint $table) {
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::table('user_companies', function (Blueprint $table) {
|
||||
$table->dropPrimary(['user_id', 'company_id', 'user_type']);
|
||||
$table->primary(['user_id', 'company_id']);
|
||||
});
|
||||
|
||||
Schema::table('user_companies', function (Blueprint $table) {
|
||||
$table->dropColumn('user_type');
|
||||
});
|
||||
|
||||
Schema::table('user_dashboards', function (Blueprint $table) {
|
||||
$table->dropPrimary(['user_id', 'company_id', 'user_type']);
|
||||
$table->primary(['user_id', 'company_id']);
|
||||
});
|
||||
|
||||
Schema::table('user_dashboards', function (Blueprint $table) {
|
||||
$table->dropColumn('user_type');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
//
|
||||
}
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user