From ce5ed15968fc2cf02c6666d9fe20ab65cfaaa0bd Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Tue, 1 Jun 2021 09:19:52 +1000 Subject: [PATCH 1/8] Removed ucfirst --- resources/views/updates/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/updates/index.blade.php b/resources/views/updates/index.blade.php index 3bb9c1ba..0469c7a2 100644 --- a/resources/views/updates/index.blade.php +++ b/resources/views/updates/index.blade.php @@ -5,7 +5,7 @@

Laravel CRM {{ ucfirst(__('laravel-crm::lang.updates')) }}

-

{{ 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')) }}
From a315c621226ef243be4f141877e2e4997c5d6d9d Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Tue, 13 Jul 2021 17:41:15 +1000 Subject: [PATCH 2/8] Support for Jetstream/Spark teams --- config/landlord.php | 16 ++++++++++++++++ config/laravel-crm.php | 23 +++++++++++++++++++++++ src/Models/Activity.php | 2 ++ src/Models/Address.php | 2 ++ src/Models/CustomField.php | 2 ++ src/Models/CustomFieldValue.php | 2 ++ src/Models/Deal.php | 2 ++ src/Models/DealProduct.php | 2 ++ src/Models/Email.php | 2 ++ src/Models/Label.php | 5 +++++ src/Models/Lead.php | 2 ++ src/Models/LeadSource.php | 2 ++ src/Models/LeadStatus.php | 5 +++++ src/Models/Note.php | 2 ++ src/Models/Organisation.php | 2 ++ src/Models/Person.php | 2 ++ src/Models/Phone.php | 2 ++ src/Models/Product.php | 2 ++ src/Models/ProductCategory.php | 2 ++ src/Models/ProductPrice.php | 2 ++ src/Models/ProductVariation.php | 2 ++ src/Models/Setting.php | 3 +++ src/Models/Team.php | 5 +++++ src/Scopes/BelongsToTeamsScope.php | 17 +++++++++++++++++ src/Traits/BelongsToTeams.php | 26 ++++++++++++++++++++++++++ 25 files changed, 134 insertions(+) create mode 100644 config/landlord.php create mode 100644 src/Scopes/BelongsToTeamsScope.php create mode 100644 src/Traits/BelongsToTeams.php diff --git a/config/landlord.php b/config/landlord.php new file mode 100644 index 00000000..a600d92b --- /dev/null +++ b/config/landlord.php @@ -0,0 +1,16 @@ + ['team_id'], + +]; diff --git a/config/laravel-crm.php b/config/laravel-crm.php index bfcd5ea6..6caf5e63 100644 --- a/config/laravel-crm.php +++ b/config/laravel-crm.php @@ -16,6 +16,29 @@ 'crm_owner' => env('LARAVEL_CRM_OWNER', ''), + /* + |-------------------------------------------------------------------------- + | Teams Support + |-------------------------------------------------------------------------- + | + | This value relates to the "teams" feature in Laravel Jetstream or Spark. + | Only set this to true if you are using this feature as it will break + | your installation if not. It basically allows you to run a multi-tenant + | crm, and the teams can be different "accounts". You can switch between + | different teams/accounts and have different users, contacts, leads, etc + | in each account. + | + | PLEASE NOTE! This has nothing to do with the user teams feature within + | the crm itself, which is simply a way of grouping users within the crm. + | + | For Jetstream see https://jetstream.laravel.com/2.x/features/teams.html + | + | For Spark see https://spark-classic.laravel.com/docs/11.0/teams + | + */ + + 'teams' => env('LARAVEL_CRM_TEAMS', false), + /* |-------------------------------------------------------------------------- | Route Prefix 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..ccd57794 100644 --- a/src/Models/Setting.php +++ b/src/Models/Setting.php @@ -3,9 +3,12 @@ namespace VentureDrake\LaravelCrm\Models; use Illuminate\Database\Eloquent\Model; +use VentureDrake\LaravelCrm\Traits\BelongsToTeams; class Setting extends Model { + use BelongsToTeams; + protected $guarded = ['id']; 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/Scopes/BelongsToTeamsScope.php b/src/Scopes/BelongsToTeamsScope.php new file mode 100644 index 00000000..19b124a0 --- /dev/null +++ b/src/Scopes/BelongsToTeamsScope.php @@ -0,0 +1,17 @@ +user()->currentTeam) { + $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; + }); + } +} From 75418f1e73269e8edad38646158b9b7400c86b5e Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Wed, 14 Jul 2021 09:17:44 +1000 Subject: [PATCH 3/8] Support for global settings when in teams mode --- ...bal_to_laravel_crm_settings_table.php.stub | 32 +++++++ src/LaravelCrmServiceProvider.php | 4 + src/Models/Setting.php | 20 ++++ src/Observers/SettingObserver.php | 96 +++++++++++++++++++ src/Scopes/BelongsToTeamsScope.php | 10 +- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 database/migrations/add_global_to_laravel_crm_settings_table.php.stub create mode 100644 src/Observers/SettingObserver.php diff --git a/database/migrations/add_global_to_laravel_crm_settings_table.php.stub b/database/migrations/add_global_to_laravel_crm_settings_table.php.stub new file mode 100644 index 00000000..869d77b9 --- /dev/null +++ b/database/migrations/add_global_to_laravel_crm_settings_table.php.stub @@ -0,0 +1,32 @@ +boolean('global')->after('team_id')->default(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table(config('laravel-crm.db_table_prefix').'settings', function (Blueprint $table) { + $table->dropColumn(['global']); + }); + } +} diff --git a/src/LaravelCrmServiceProvider.php b/src/LaravelCrmServiceProvider.php index 350604f1..d2d29360 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 { @@ -107,6 +109,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 @@ -139,6 +142,7 @@ class_alias(config("auth.providers.users.model"), 'App\User'); Organisation::observe(OrganisationObserver::class); Phone::observe(PhoneObserver::class); Email::observe(EmailObserver::class); + Setting::observe(SettingObserver::class); // Register the model factories if (app()->version() < 8) { diff --git a/src/Models/Setting.php b/src/Models/Setting.php index ccd57794..23b2b9e6 100644 --- a/src/Models/Setting.php +++ b/src/Models/Setting.php @@ -10,6 +10,26 @@ 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/Observers/SettingObserver.php b/src/Observers/SettingObserver.php new file mode 100644 index 00000000..0170f737 --- /dev/null +++ b/src/Observers/SettingObserver.php @@ -0,0 +1,96 @@ +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; + } + } + } + + /** + * Handle the Setting "created" event. + * + * @param \App\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) + { + } + + /** + * Handle the Setting "updated" event. + * + * @param \App\Models\Setting $setting + * @return void + */ + public function updated(Setting $setting) + { + // + } + + /** + * Handle the Setting "deleted" event. + * + * @param \App\Models\Setting $setting + * @return void + */ + public function deleted(Setting $setting) + { + // + } + + /** + * Handle the Setting "restored" event. + * + * @param \App\Models\Setting $setting + * @return void + */ + public function restored(Setting $setting) + { + // + } + + /** + * Handle the Setting "force deleted" event. + * + * @param \App\Models\Setting $setting + * @return void + */ + public function forceDeleted(Setting $setting) + { + // + } +} diff --git a/src/Scopes/BelongsToTeamsScope.php b/src/Scopes/BelongsToTeamsScope.php index 19b124a0..69c0c703 100644 --- a/src/Scopes/BelongsToTeamsScope.php +++ b/src/Scopes/BelongsToTeamsScope.php @@ -5,13 +5,21 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Scope; +use Illuminate\Support\Facades\Schema; class BelongsToTeamsScope implements Scope { public function apply(Builder $builder, Model $model) { if (config('laravel-crm.teams') && auth()->user()->currentTeam) { - $builder->where('team_id', auth()->user()->currentTeam->id); + 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); + } } } } From f1f1e9768df26b2b3242aa4a02d9af1aa6bf2e83 Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Wed, 14 Jul 2021 09:21:45 +1000 Subject: [PATCH 4/8] Update team name --- src/Http/Controllers/SettingController.php | 7 +++++++ 1 file changed, 7 insertions(+) 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(); From 6540172b208ab4f24fc66dfba3d39024a263ccc8 Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Wed, 14 Jul 2021 09:59:37 +1000 Subject: [PATCH 5/8] Fixed observers --- src/LaravelCrmServiceProvider.php | 24 +++++++------- src/Observers/EmailObserver.php | 32 +++++++++++++++++- src/Observers/LeadObserver.php | 19 ++++++++++- src/Observers/OrganisationObserver.php | 32 +++++++++++++++++- src/Observers/PersonObserver.php | 30 ++++++++++++++++- src/Observers/PhoneObserver.php | 32 +++++++++++++++++- src/Observers/SettingObserver.php | 45 +++++++++++++++----------- 7 files changed, 177 insertions(+), 37 deletions(-) diff --git a/src/LaravelCrmServiceProvider.php b/src/LaravelCrmServiceProvider.php index d2d29360..23de17e7 100644 --- a/src/LaravelCrmServiceProvider.php +++ b/src/LaravelCrmServiceProvider.php @@ -77,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'), @@ -130,19 +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); - Setting::observe(SettingObserver::class); + $this->commands([ + LaravelCrmInstall::class, + ]); // Register the model factories if (app()->version() < 8) { 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..8bf09ca9 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,17 @@ 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 +98,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 index 0170f737..e3f65c88 100644 --- a/src/Observers/SettingObserver.php +++ b/src/Observers/SettingObserver.php @@ -2,6 +2,7 @@ namespace VentureDrake\LaravelCrm\Observers; +use Illuminate\Support\Facades\Schema; use VentureDrake\LaravelCrm\Models\Setting; class SettingObserver @@ -9,30 +10,18 @@ class SettingObserver /** * Handle the email "creating" event. * - * @param \VentureDrake\LaravelCrm\Setting $setting + * @param \VentureDrake\LaravelCrm\Models\Setting $setting * @return void */ public function creating(Setting $setting) { - if ($setting->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; - } - } + $this->setGlobal($setting); } /** * Handle the Setting "created" event. * - * @param \App\Models\Setting $setting + * @param \VentureDrake\LaravelCrm\Models\Setting $setting * @return void */ public function created(Setting $setting) @@ -48,12 +37,13 @@ public function created(Setting $setting) */ public function updating(Setting $setting) { + $this->setGlobal($setting); } /** * Handle the Setting "updated" event. * - * @param \App\Models\Setting $setting + * @param \VentureDrake\LaravelCrm\Models\Setting $setting * @return void */ public function updated(Setting $setting) @@ -64,7 +54,7 @@ public function updated(Setting $setting) /** * Handle the Setting "deleted" event. * - * @param \App\Models\Setting $setting + * @param \VentureDrake\LaravelCrm\Models\Setting $setting * @return void */ public function deleted(Setting $setting) @@ -75,7 +65,7 @@ public function deleted(Setting $setting) /** * Handle the Setting "restored" event. * - * @param \App\Models\Setting $setting + * @param \VentureDrake\LaravelCrm\Models\Setting $setting * @return void */ public function restored(Setting $setting) @@ -86,11 +76,28 @@ public function restored(Setting $setting) /** * Handle the Setting "force deleted" event. * - * @param \App\Models\Setting $setting + * @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; + } + } + } } From c95010eb87d98b0617e48b1516102ba674ddcac7 Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Wed, 14 Jul 2021 10:00:24 +1000 Subject: [PATCH 6/8] php cs --- src/Observers/PersonObserver.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Observers/PersonObserver.php b/src/Observers/PersonObserver.php index 8bf09ca9..61b0c564 100644 --- a/src/Observers/PersonObserver.php +++ b/src/Observers/PersonObserver.php @@ -87,7 +87,6 @@ public function deleted(Person $person) */ public function restoring(Person $person) { - } /** From 576f141ab7c610ea50c055d468b1d2bd6abef88d Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Wed, 14 Jul 2021 10:28:17 +1000 Subject: [PATCH 7/8] Release details --- CHANGELOG.md | 7 +++++++ README.md | 38 +++++++++++--------------------------- config/package.php | 2 +- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8de3eb90..a700b12f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed ### Removed ---> +## 0.6.0 - 2021-07-14 +### Added +- Support for Jetstream/Spark teams +### Fixed +- Model observers - https://github.com/venturedrake/laravel-crm/issues/29 +- Assign role instead of sync - https://github.com/venturedrake/laravel-crm/pull/28 + ## 0.5.1 - 2021-05-31 ### Fixed - Missing key in lang file diff --git a/README.md b/README.md index 1d92976f..a3690f87 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ This package will add CRM functionality to your laravel projects - Build a custom CRM for your business or your clients - Use as an integrated CRM for your Laravel powered business (Saas, E-commerce, etc) - Use as a CRM for your Laravel development business +- Run a multi-tenant CRM Saas business ## Features @@ -27,6 +28,7 @@ This package will add CRM functionality to your laravel projects - Users & Teams - Secure registration & login - Reset forgotten password + - Laravel Jetstream/Spark teams support ## Installation (10-15mins) @@ -45,7 +47,7 @@ https://spatie.be/docs/laravel-permission/v4/installation-laravel #### Step 4. Require the current package using composer: ```bash -composer require venturedrake/laravel-crm:^0.5 +composer require venturedrake/laravel-crm:^0.6 ``` #### Step 5. Publish the migrations, config & assets @@ -127,12 +129,12 @@ Note if you modified the route_prefix setting from the default the above url wil ## Upgrade -### Upgrading from 0.3 +### Upgrading from >= 0.2 #### Step 1. Run the following to the update migrations and publish assets: ```bash -composer require venturedrake/laravel-crm::^0.5 +composer require venturedrake/laravel-crm::^0.6 php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="migrations" php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="assets" --force php artisan migrate @@ -144,26 +146,12 @@ php artisan migrate php artisan db:seed --class="VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmTablesSeeder" ``` -### Upgrading from 0.1 to 0.3 +### Upgrading from < 0.2 -#### Step 1. Run the following to the update migrations and publish assets: +#### Step 1. Run the following to the update package: ```bash -composer require venturedrake/laravel-crm::^0.3 -php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="migrations" -php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="assets" --force -php artisan migrate -``` - -### Upgrading from 0.1 to 0.2 - -#### Step 1. Run the following to the update package, database and add the default roles/permissions: - -```bash -composer require venturedrake/laravel-crm::^0.2 -php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="migrations" -php artisan migrate -php artisan db:seed --class="VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmTablesSeeder" +composer require venturedrake/laravel-crm::^0.6 ``` #### Step 2. Delete previously published package views located in resources/views/vendor/laravel-crm/* @@ -172,18 +160,14 @@ php artisan db:seed --class="VentureDrake\LaravelCrm\Database\Seeders\LaravelCrm #### Step 4. Add HasCrmAccess, HasCrmTeams & HasRoles traits to App\User model, see installation Step 8. -### Upgrading from 0.1.x to 0.1.2 - -#### Step 1. Run the following to update the package & database - +#### Step 5. Run the following to the update database and add the default roles/permissions: ```bash -composer require venturedrake/laravel-crm::^0.1 php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="migrations" +php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="assets" --force php artisan migrate +php artisan db:seed --class="VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmTablesSeeder" ``` -#### Step 2. Delete previously published package views located in folder resources/views/vendor/laravel-crm/* - ## Testing diff --git a/config/package.php b/config/package.php index 5ed3e37d..acec4199 100644 --- a/config/package.php +++ b/config/package.php @@ -13,6 +13,6 @@ | */ - 'version' => '0.5.1', + 'version' => '0.6.0', ]; From 89c754401d9f35e166a56a005297d76c2bd7c732 Mon Sep 17 00:00:00 2001 From: Andrew Drake Date: Wed, 14 Jul 2021 10:28:38 +1000 Subject: [PATCH 8/8] Removed landlord config --- config/landlord.php | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 config/landlord.php diff --git a/config/landlord.php b/config/landlord.php deleted file mode 100644 index a600d92b..00000000 --- a/config/landlord.php +++ /dev/null @@ -1,16 +0,0 @@ - ['team_id'], - -];