-
{{ ucfirst(__('laravel-crm::lang.current_version')) }} {{ \VentureDrake\LaravelCrm\Models\Setting::where('name','version')->first()->value }} {{ (\VentureDrake\LaravelCrm\Models\Setting::where('name','version')->first()->value == \VentureDrake\LaravelCrm\Models\Setting::where('name','version_latest')->first()->value) ? ucfirst(__('laravel-crm::lang.is_the_latest_version')) : null }}
+
{{ ucfirst(__('laravel-crm::lang.current_version')) }} {{ \VentureDrake\LaravelCrm\Models\Setting::where('name','version')->first()->value }} {{ (\VentureDrake\LaravelCrm\Models\Setting::where('name','version')->first()->value == \VentureDrake\LaravelCrm\Models\Setting::where('name','version_latest')->first()->value) ? __('laravel-crm::lang.is_the_latest_version') : null }}
@if(\VentureDrake\LaravelCrm\Models\Setting::where('name','version')->first()->value < \VentureDrake\LaravelCrm\Models\Setting::where('name','version_latest')->first()->value)
{{ ucfirst(__('laravel-crm::lang.updated_version_of_laravel_crm_is_available')) }}
diff --git a/src/Http/Controllers/SettingController.php b/src/Http/Controllers/SettingController.php
index 85ff732b..8e227567 100644
--- a/src/Http/Controllers/SettingController.php
+++ b/src/Http/Controllers/SettingController.php
@@ -2,6 +2,7 @@
namespace VentureDrake\LaravelCrm\Http\Controllers;
+use DB;
use VentureDrake\LaravelCrm\Http\Requests\UpdateSettingRequest;
use VentureDrake\LaravelCrm\Services\SettingService;
@@ -51,6 +52,12 @@ public function update(UpdateSettingRequest $request)
$this->settingService->set('country', $request->country);
$this->settingService->set('currency', $request->currency);
+ if ($request->organisation_name && config('laravel-crm.teams') && auth()->user()->currentTeam) {
+ DB::table("teams")
+ ->where("id", auth()->user()->currentTeam->id)
+ ->update(["name" => $request->organisation_name]);
+ }
+
flash(ucfirst(trans('laravel-crm::lang.settings_updated')))->success()->important();
return back();
diff --git a/src/LaravelCrmServiceProvider.php b/src/LaravelCrmServiceProvider.php
index 350604f1..23de17e7 100644
--- a/src/LaravelCrmServiceProvider.php
+++ b/src/LaravelCrmServiceProvider.php
@@ -19,11 +19,13 @@
use VentureDrake\LaravelCrm\Models\Organisation;
use VentureDrake\LaravelCrm\Models\Person;
use VentureDrake\LaravelCrm\Models\Phone;
+use VentureDrake\LaravelCrm\Models\Setting;
use VentureDrake\LaravelCrm\Observers\EmailObserver;
use VentureDrake\LaravelCrm\Observers\LeadObserver;
use VentureDrake\LaravelCrm\Observers\OrganisationObserver;
use VentureDrake\LaravelCrm\Observers\PersonObserver;
use VentureDrake\LaravelCrm\Observers\PhoneObserver;
+use VentureDrake\LaravelCrm\Observers\SettingObserver;
class LaravelCrmServiceProvider extends ServiceProvider
{
@@ -75,6 +77,14 @@ class_alias(config("auth.providers.users.model"), 'App\User');
$this->registerRoutes();
+ // Register Observers
+ Lead::observe(LeadObserver::class);
+ Person::observe(PersonObserver::class);
+ Organisation::observe(OrganisationObserver::class);
+ Phone::observe(PhoneObserver::class);
+ Email::observe(EmailObserver::class);
+ Setting::observe(SettingObserver::class);
+
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/../config/laravel-crm.php' => config_path('laravel-crm.php'),
@@ -107,6 +117,7 @@ class_alias(config("auth.providers.users.model"), 'App\User');
__DIR__ . '/../database/migrations/create_laravel_crm_product_prices_table.php.stub' => $this->getMigrationFileName($filesystem, 'create_laravel_crm_product_prices_table.php', 8),
__DIR__ . '/../database/migrations/create_laravel_crm_product_variations_table.php.stub' => $this->getMigrationFileName($filesystem, 'create_laravel_crm_product_variations_table.php', 9),
__DIR__ . '/../database/migrations/create_laravel_crm_deal_products_table.php.stub' => $this->getMigrationFileName($filesystem, 'create_laravel_crm_deal_products_table.php', 10),
+ __DIR__ . '/../database/migrations/add_global_to_laravel_crm_settings_table.php.stub' => $this->getMigrationFileName($filesystem, 'add_global_to_laravel_crm_settings_table.php', 11),
], 'migrations');
// Publishing the seeders
@@ -127,18 +138,9 @@ class_alias(config("auth.providers.users.model"), 'App\User');
}
// Registering package commands.
- if ($this->app->runningInConsole()) {
- $this->commands([
- LaravelCrmInstall::class,
- ]);
- }
-
- // Register Observers
- Lead::observe(LeadObserver::class);
- Person::observe(PersonObserver::class);
- Organisation::observe(OrganisationObserver::class);
- Phone::observe(PhoneObserver::class);
- Email::observe(EmailObserver::class);
+ $this->commands([
+ LaravelCrmInstall::class,
+ ]);
// Register the model factories
if (app()->version() < 8) {
diff --git a/src/Models/Activity.php b/src/Models/Activity.php
index 5ac06304..7b8e8276 100644
--- a/src/Models/Activity.php
+++ b/src/Models/Activity.php
@@ -6,10 +6,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class Activity extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
public function getTable()
{
diff --git a/src/Models/Address.php b/src/Models/Address.php
index 7b820c4a..7f675d02 100644
--- a/src/Models/Address.php
+++ b/src/Models/Address.php
@@ -4,12 +4,14 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
use VentureDrake\LaravelEncryptable\Traits\LaravelEncryptableTrait;
class Address extends Model
{
use SoftDeletes;
use LaravelEncryptableTrait;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/CustomField.php b/src/Models/CustomField.php
index 1857b18f..04751d12 100644
--- a/src/Models/CustomField.php
+++ b/src/Models/CustomField.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class CustomField extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/CustomFieldValue.php b/src/Models/CustomFieldValue.php
index a75022c2..cf2c66b3 100644
--- a/src/Models/CustomFieldValue.php
+++ b/src/Models/CustomFieldValue.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class CustomFieldValue extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Deal.php b/src/Models/Deal.php
index d1c79425..26413c37 100644
--- a/src/Models/Deal.php
+++ b/src/Models/Deal.php
@@ -5,12 +5,14 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
use VentureDrake\LaravelCrm\Traits\HasCrmFields;
class Deal extends Model
{
use SoftDeletes;
use HasCrmFields;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/DealProduct.php b/src/Models/DealProduct.php
index 56bf433a..2411fb1e 100644
--- a/src/Models/DealProduct.php
+++ b/src/Models/DealProduct.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class DealProduct extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Email.php b/src/Models/Email.php
index 12a04f36..3d2c0e00 100644
--- a/src/Models/Email.php
+++ b/src/Models/Email.php
@@ -4,12 +4,14 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
use VentureDrake\LaravelEncryptable\Traits\LaravelEncryptableTrait;
class Email extends Model
{
use SoftDeletes;
use LaravelEncryptableTrait;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Label.php b/src/Models/Label.php
index 92f0409d..ced81a9b 100644
--- a/src/Models/Label.php
+++ b/src/Models/Label.php
@@ -3,9 +3,14 @@
namespace VentureDrake\LaravelCrm\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class Label extends Model
{
+ use SoftDeletes;
+ use BelongsToTeams;
+
protected $guarded = ['id'];
public function getTable()
diff --git a/src/Models/Lead.php b/src/Models/Lead.php
index 67979f38..90265341 100644
--- a/src/Models/Lead.php
+++ b/src/Models/Lead.php
@@ -4,12 +4,14 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
use VentureDrake\LaravelCrm\Traits\HasCrmFields;
class Lead extends Model
{
use SoftDeletes;
use HasCrmFields;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/LeadSource.php b/src/Models/LeadSource.php
index 50300864..96c6794e 100644
--- a/src/Models/LeadSource.php
+++ b/src/Models/LeadSource.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class LeadSource extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/LeadStatus.php b/src/Models/LeadStatus.php
index 7f895e02..ee278ba0 100644
--- a/src/Models/LeadStatus.php
+++ b/src/Models/LeadStatus.php
@@ -3,9 +3,14 @@
namespace VentureDrake\LaravelCrm\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class LeadStatus extends Model
{
+ use SoftDeletes;
+ use BelongsToTeams;
+
protected $guarded = ['id'];
public function getTable()
diff --git a/src/Models/Note.php b/src/Models/Note.php
index 9986141f..0982e4ed 100644
--- a/src/Models/Note.php
+++ b/src/Models/Note.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class Note extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Organisation.php b/src/Models/Organisation.php
index c38bfdd7..abde00eb 100644
--- a/src/Models/Organisation.php
+++ b/src/Models/Organisation.php
@@ -4,12 +4,14 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
use VentureDrake\LaravelEncryptable\Traits\LaravelEncryptableTrait;
class Organisation extends Model
{
use SoftDeletes;
use LaravelEncryptableTrait;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Person.php b/src/Models/Person.php
index 6a216470..291b362e 100644
--- a/src/Models/Person.php
+++ b/src/Models/Person.php
@@ -5,12 +5,14 @@
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
use VentureDrake\LaravelEncryptable\Traits\LaravelEncryptableTrait;
class Person extends Model
{
use SoftDeletes;
use LaravelEncryptableTrait;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Phone.php b/src/Models/Phone.php
index dd1e0615..c878d99f 100644
--- a/src/Models/Phone.php
+++ b/src/Models/Phone.php
@@ -4,12 +4,14 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
use VentureDrake\LaravelEncryptable\Traits\LaravelEncryptableTrait;
class Phone extends Model
{
use SoftDeletes;
use LaravelEncryptableTrait;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Product.php b/src/Models/Product.php
index a230f804..6e76f05b 100644
--- a/src/Models/Product.php
+++ b/src/Models/Product.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class Product extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/ProductCategory.php b/src/Models/ProductCategory.php
index 5380524b..e8e5f311 100644
--- a/src/Models/ProductCategory.php
+++ b/src/Models/ProductCategory.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class ProductCategory extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/ProductPrice.php b/src/Models/ProductPrice.php
index 55961696..b326d78e 100644
--- a/src/Models/ProductPrice.php
+++ b/src/Models/ProductPrice.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class ProductPrice extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/ProductVariation.php b/src/Models/ProductVariation.php
index 0d4ffa25..6582bec5 100644
--- a/src/Models/ProductVariation.php
+++ b/src/Models/ProductVariation.php
@@ -4,10 +4,12 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class ProductVariation extends Model
{
use SoftDeletes;
+ use BelongsToTeams;
protected $guarded = ['id'];
diff --git a/src/Models/Setting.php b/src/Models/Setting.php
index 4689f098..23b2b9e6 100644
--- a/src/Models/Setting.php
+++ b/src/Models/Setting.php
@@ -3,10 +3,33 @@
namespace VentureDrake\LaravelCrm\Models;
use Illuminate\Database\Eloquent\Model;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class Setting extends Model
{
+ use BelongsToTeams;
+
protected $guarded = ['id'];
+
+ protected static function boot()
+ {
+ parent::boot();
+ static::creating(function ($model) {
+ if ($model->global) {
+ switch ($model->name) {
+ case "app_name":
+ case "app_env":
+ case "app_url":
+ case "version":
+ case "install_id":
+ case "version_latest":
+ $model->global = 1;
+
+ break;
+ }
+ }
+ });
+ }
public function getTable()
{
diff --git a/src/Models/Team.php b/src/Models/Team.php
index b3391517..9fed2530 100644
--- a/src/Models/Team.php
+++ b/src/Models/Team.php
@@ -3,9 +3,14 @@
namespace VentureDrake\LaravelCrm\Models;
use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
+use VentureDrake\LaravelCrm\Traits\BelongsToTeams;
class Team extends Model
{
+ use SoftDeletes;
+ use BelongsToTeams;
+
/**
* The table associated with the team model.
*
diff --git a/src/Observers/EmailObserver.php b/src/Observers/EmailObserver.php
index ab03334e..7a04856b 100644
--- a/src/Observers/EmailObserver.php
+++ b/src/Observers/EmailObserver.php
@@ -30,6 +30,19 @@ public function created(Email $email)
//
}
+ /**
+ * Handle the email "updating" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Email $email
+ * @return void
+ */
+ public function updating(Email $email)
+ {
+ if (! app()->runningInConsole()) {
+ $email->user_updated_id = auth()->user()->id ?? null;
+ }
+ }
+
/**
* Handle the email "updated" event.
*
@@ -41,6 +54,20 @@ public function updated(Email $email)
//
}
+ /**
+ * Handle the email "deleting" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Email $email
+ * @return void
+ */
+ public function deleting(Email $email)
+ {
+ if (! app()->runningInConsole()) {
+ $email->user_deleted_id = auth()->user()->id ?? null;
+ $email->saveQuietly();
+ }
+ }
+
/**
* Handle the email "deleted" event.
*
@@ -60,7 +87,10 @@ public function deleted(Email $email)
*/
public function restored(Email $email)
{
- //
+ if (! app()->runningInConsole()) {
+ $email->user_restored_id = auth()->user()->id ?? null;
+ $email->saveQuietly();
+ }
}
/**
diff --git a/src/Observers/LeadObserver.php b/src/Observers/LeadObserver.php
index e49c4b12..69ebfb23 100644
--- a/src/Observers/LeadObserver.php
+++ b/src/Observers/LeadObserver.php
@@ -54,6 +54,20 @@ public function updated(Lead $lead)
//
}
+ /**
+ * Handle the lead "deleting" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Lead $lead
+ * @return void
+ */
+ public function deleting(Lead $lead)
+ {
+ if (! app()->runningInConsole()) {
+ $lead->user_deleted_id = auth()->user()->id ?? null;
+ $lead->saveQuietly();
+ }
+ }
+
/**
* Handle the lead "deleted" event.
*
@@ -73,7 +87,10 @@ public function deleted(Lead $lead)
*/
public function restored(Lead $lead)
{
- //
+ if (! app()->runningInConsole()) {
+ $lead->user_deleted_id = auth()->user()->id ?? null;
+ $lead->saveQuietly();
+ }
}
/**
diff --git a/src/Observers/OrganisationObserver.php b/src/Observers/OrganisationObserver.php
index 71f5fff8..f68d6cf1 100644
--- a/src/Observers/OrganisationObserver.php
+++ b/src/Observers/OrganisationObserver.php
@@ -30,6 +30,19 @@ public function created(Organisation $organisation)
//
}
+ /**
+ * Handle the organisation "updating" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Organisation $organisation
+ * @return void
+ */
+ public function updating(Organisation $organisation)
+ {
+ if (! app()->runningInConsole()) {
+ $organisation->user_updated_id = auth()->user()->id ?? null;
+ }
+ }
+
/**
* Handle the organisation "updated" event.
*
@@ -41,6 +54,20 @@ public function updated(Organisation $organisation)
//
}
+ /**
+ * Handle the organisation "deleting" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Organisation $organisation
+ * @return void
+ */
+ public function deleting(Organisation $organisation)
+ {
+ if (! app()->runningInConsole()) {
+ $organisation->user_deleted_id = auth()->user()->id ?? null;
+ $organisation->saveQuietly();
+ }
+ }
+
/**
* Handle the organisation "deleted" event.
*
@@ -60,7 +87,10 @@ public function deleted(Organisation $organisation)
*/
public function restored(Organisation $organisation)
{
- //
+ if (! app()->runningInConsole()) {
+ $organisation->user_deleted_id = auth()->user()->id ?? null;
+ $organisation->saveQuietly();
+ }
}
/**
diff --git a/src/Observers/PersonObserver.php b/src/Observers/PersonObserver.php
index 876eb73b..61b0c564 100644
--- a/src/Observers/PersonObserver.php
+++ b/src/Observers/PersonObserver.php
@@ -54,6 +54,20 @@ public function updated(Person $person)
//
}
+ /**
+ * Handle the person "deleting" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Person $person
+ * @return void
+ */
+ public function deleting(Person $person)
+ {
+ if (! app()->runningInConsole()) {
+ $person->user_deleted_id = auth()->user()->id ?? null;
+ $person->saveQuietly();
+ }
+ }
+
/**
* Handle the person "deleted" event.
*
@@ -65,6 +79,16 @@ public function deleted(Person $person)
//
}
+ /**
+ * Handle the person "restoring" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Person $person
+ * @return void
+ */
+ public function restoring(Person $person)
+ {
+ }
+
/**
* Handle the person "restored" event.
*
@@ -73,7 +97,10 @@ public function deleted(Person $person)
*/
public function restored(Person $person)
{
- //
+ if (! app()->runningInConsole()) {
+ $person->user_restored_id = auth()->user()->id ?? null;
+ $person->saveQuietly();
+ }
}
/**
diff --git a/src/Observers/PhoneObserver.php b/src/Observers/PhoneObserver.php
index 8801ccb7..00de871d 100644
--- a/src/Observers/PhoneObserver.php
+++ b/src/Observers/PhoneObserver.php
@@ -30,6 +30,19 @@ public function created(Phone $phone)
//
}
+ /**
+ * Handle the phone "updating" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Phone $phone
+ * @return void
+ */
+ public function updating(Phone $phone)
+ {
+ if (! app()->runningInConsole()) {
+ $phone->user_updated_id = auth()->user()->id ?? null;
+ }
+ }
+
/**
* Handle the phone "updated" event.
*
@@ -41,6 +54,20 @@ public function updated(Phone $phone)
//
}
+ /**
+ * Handle the phone "deleting" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Phone $phone
+ * @return void
+ */
+ public function deleting(Phone $phone)
+ {
+ if (! app()->runningInConsole()) {
+ $phone->user_deleted_id = auth()->user()->id ?? null;
+ $phone->saveQuietly();
+ }
+ }
+
/**
* Handle the phone "deleted" event.
*
@@ -60,7 +87,10 @@ public function deleted(Phone $phone)
*/
public function restored(Phone $phone)
{
- //
+ if (! app()->runningInConsole()) {
+ $phone->user_restored_id = auth()->user()->id ?? null;
+ $phone->saveQuietly();
+ }
}
/**
diff --git a/src/Observers/SettingObserver.php b/src/Observers/SettingObserver.php
new file mode 100644
index 00000000..e3f65c88
--- /dev/null
+++ b/src/Observers/SettingObserver.php
@@ -0,0 +1,103 @@
+setGlobal($setting);
+ }
+
+ /**
+ * Handle the Setting "created" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Models\Setting $setting
+ * @return void
+ */
+ public function created(Setting $setting)
+ {
+ //
+ }
+
+ /**
+ * Handle the email "updating" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Setting $setting
+ * @return void
+ */
+ public function updating(Setting $setting)
+ {
+ $this->setGlobal($setting);
+ }
+
+ /**
+ * Handle the Setting "updated" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Models\Setting $setting
+ * @return void
+ */
+ public function updated(Setting $setting)
+ {
+ //
+ }
+
+ /**
+ * Handle the Setting "deleted" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Models\Setting $setting
+ * @return void
+ */
+ public function deleted(Setting $setting)
+ {
+ //
+ }
+
+ /**
+ * Handle the Setting "restored" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Models\Setting $setting
+ * @return void
+ */
+ public function restored(Setting $setting)
+ {
+ //
+ }
+
+ /**
+ * Handle the Setting "force deleted" event.
+ *
+ * @param \VentureDrake\LaravelCrm\Models\Setting $setting
+ * @return void
+ */
+ public function forceDeleted(Setting $setting)
+ {
+ //
+ }
+
+ protected function setGlobal(Setting $setting)
+ {
+ if (Schema::hasColumn($setting->getTable(), 'global')) {
+ switch ($setting->name) {
+ case "app_name":
+ case "app_env":
+ case "app_url":
+ case "version":
+ case "install_id":
+ case "version_latest":
+ $setting->global = 1;
+
+ break;
+ }
+ }
+ }
+}
diff --git a/src/Scopes/BelongsToTeamsScope.php b/src/Scopes/BelongsToTeamsScope.php
new file mode 100644
index 00000000..69c0c703
--- /dev/null
+++ b/src/Scopes/BelongsToTeamsScope.php
@@ -0,0 +1,25 @@
+user()->currentTeam) {
+ if (Schema::hasColumn($model->getTable(), 'global')) {
+ $builder->where(function ($query) {
+ $query->orWhere('team_id', auth()->user()->currentTeam->id)
+ ->orWhere('global', 1);
+ });
+ } else {
+ $builder->where('team_id', auth()->user()->currentTeam->id);
+ }
+ }
+ }
+}
diff --git a/src/Traits/BelongsToTeams.php b/src/Traits/BelongsToTeams.php
new file mode 100644
index 00000000..6ee11ef3
--- /dev/null
+++ b/src/Traits/BelongsToTeams.php
@@ -0,0 +1,26 @@
+team_id = auth()->user()->currentTeam->id ?? null;
+ });
+ }
+}