From 7f954ad3e475a40212dd2e41f74fc03086e13da3 Mon Sep 17 00:00:00 2001 From: Chris H Date: Mon, 22 Mar 2021 21:22:15 -0500 Subject: [PATCH 1/4] Update Email address relationship #46 --- database/factories/ContactFactory.php | 16 ++++++++-------- .../2020_05_20_100000_create_contacts_table.php | 2 +- src/Models/Contact.php | 5 +++++ src/Nova/Contact.php | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/database/factories/ContactFactory.php b/database/factories/ContactFactory.php index c9f610c..a79b1cd 100644 --- a/database/factories/ContactFactory.php +++ b/database/factories/ContactFactory.php @@ -15,14 +15,14 @@ class ContactFactory extends Factory public function definition() { return [ - 'form_type' => $this->faker->randomElement(FormType::getValues()), - 'location_id' => randomOrCreate(app('location')), - 'email' => $this->faker->email, - 'first_name' => $this->faker->firstName, - 'last_name' => $this->faker->lastName, - 'phone' => '555-555-5555', - 'company_name' => $this->faker->company, - 'message' => $this->faker->paragraph, + 'form_type' => $this->faker->randomElement(FormType::getValues()), + 'location_id' => randomOrCreate(app('location')), + 'email_address_id' => randomOrCreate(app('email_address')), + 'first_name' => $this->faker->firstName, + 'last_name' => $this->faker->lastName, + 'phone' => '555-555-5555', + 'company_name' => $this->faker->company, + 'message' => $this->faker->paragraph, ]; } } diff --git a/database/migrations/2020_05_20_100000_create_contacts_table.php b/database/migrations/2020_05_20_100000_create_contacts_table.php index de4744a..e85e996 100644 --- a/database/migrations/2020_05_20_100000_create_contacts_table.php +++ b/database/migrations/2020_05_20_100000_create_contacts_table.php @@ -15,7 +15,7 @@ public function up() $table->string('form_type')->index(); $table->string('reference_number')->index()->unique(); // Generated by system. This is identifier used to communicate with customer about their contact form. Reference number is emailed to them. $table->foreignIdFor(app('location'))->index(); - $table->string('email'); + $table->foreignIdFor(app('email_address'))->index(); $table->foreignIdFor(app('user'))->nullable()->index(); $table->string('first_name')->nullable(); $table->string('last_name')->nullable(); diff --git a/src/Models/Contact.php b/src/Models/Contact.php index a5f8c3b..733e2d0 100644 --- a/src/Models/Contact.php +++ b/src/Models/Contact.php @@ -77,6 +77,11 @@ public function getContactStatusHistory(): Collection return $this->getStatusHistory(ContactStatus::statusType()); } + public function email() + { + return $this->hasOne(app('email_address')); + } + public function response() { return $this->hasOne(ContactResponse::class); diff --git a/src/Nova/Contact.php b/src/Nova/Contact.php index 2de1e96..8e67c2b 100644 --- a/src/Nova/Contact.php +++ b/src/Nova/Contact.php @@ -71,7 +71,7 @@ public function fields(Request $request) nova('location') ? BelongsTo::make('Location', 'location', nova('location'))->required()->hideWhenUpdating() : null, nova('user') ? BelongsTo::make('User', 'user', nova('user'))->required()->hideWhenUpdating() : null, PhoneNumber::make('Phone')->format('###-###-####')->disableValidation()->useMaskPlaceholder()->linkOnDetail()->hideWhenUpdating(), - Email::make('Email', 'user.email')->clickable()->hideWhenUpdating(), + nova('email_address') ? BelongsTo::make('Email Address', 'email_address', nova('email_address'))->sortable() : null, Textarea::make('Message')->rows(3)->alwaysShow()->nullable()->hideWhenUpdating(), new Panel('Submission Details', $this->submissionFields()), From 5baa87dbb99e242cb51b30e21207a3be2919bd51 Mon Sep 17 00:00:00 2001 From: chx2 Date: Tue, 23 Mar 2021 02:22:42 +0000 Subject: [PATCH 2/4] Fix styling --- src/Nova/Contact.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Nova/Contact.php b/src/Nova/Contact.php index 8e67c2b..3b152cd 100644 --- a/src/Nova/Contact.php +++ b/src/Nova/Contact.php @@ -6,7 +6,6 @@ use Dniccum\PhoneNumber\PhoneNumber; use Illuminate\Http\Request; -use Inspheric\Fields\Email; use Laravel\Nova\Fields\BelongsTo; use Laravel\Nova\Fields\Date; use Laravel\Nova\Fields\DateTime; From 825bd9581734b9ae681c5c95e9f5ee7a9c1776a5 Mon Sep 17 00:00:00 2001 From: Chris H Date: Tue, 23 Mar 2021 18:36:50 -0500 Subject: [PATCH 3/4] Remove AttachContactUsers Command #31 --- src/Commands/AttachContactUsers.php | 52 ------------------- src/FormsServiceProvider.php | 3 -- .../AttachContactUsersCommandTest.php | 35 ------------- 3 files changed, 90 deletions(-) delete mode 100644 src/Commands/AttachContactUsers.php delete mode 100644 tests/Unit/Commands/AttachContactUsersCommandTest.php diff --git a/src/Commands/AttachContactUsers.php b/src/Commands/AttachContactUsers.php deleted file mode 100644 index b2dad8f..0000000 --- a/src/Commands/AttachContactUsers.php +++ /dev/null @@ -1,52 +0,0 @@ -get(); - foreach ($contacts as $contact) { - $user = app('user')->where('email', '=', $contact->email)->first(); - if ($user) { - $contact->user_id = $user->id; - $contact->save(); - } - } - } -} diff --git a/src/FormsServiceProvider.php b/src/FormsServiceProvider.php index eb04cd7..1116c86 100644 --- a/src/FormsServiceProvider.php +++ b/src/FormsServiceProvider.php @@ -25,9 +25,6 @@ public function configureTipoffPackage(TipoffPackage $package): void \Tipoff\Forms\Nova\Contact::class, \Tipoff\Forms\Nova\ContactResponse::class, ]) - ->hasCommands([ - AttachContactUsers::class, - ]) ->name('forms') ->hasConfigFile(); } diff --git a/tests/Unit/Commands/AttachContactUsersCommandTest.php b/tests/Unit/Commands/AttachContactUsersCommandTest.php deleted file mode 100644 index d666f53..0000000 --- a/tests/Unit/Commands/AttachContactUsersCommandTest.php +++ /dev/null @@ -1,35 +0,0 @@ -artisan('attach:users'); - $this->assertDatabaseCount('contacts', 0); - } - - /** @test */ - public function user_found() - { - //Create a user and contact with same email, but not attached - $user = randomOrCreate(app('user')); - Contact::factory()->create([ - 'email' => $user->email, - ]); - - $this->artisan('attach:users'); - $contact = Contact::where('email', '=', $user->email)->first(); - $this->assertNotNull($contact->user); - } -} From 2ef70228e4d3b33b58abdf67284100366006b693 Mon Sep 17 00:00:00 2001 From: chx2 Date: Tue, 23 Mar 2021 23:37:17 +0000 Subject: [PATCH 4/4] Fix styling --- src/FormsServiceProvider.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/FormsServiceProvider.php b/src/FormsServiceProvider.php index 1116c86..24e715f 100644 --- a/src/FormsServiceProvider.php +++ b/src/FormsServiceProvider.php @@ -4,7 +4,6 @@ namespace Tipoff\Forms; -use Tipoff\Forms\Commands\AttachContactUsers; use Tipoff\Forms\Models\Contact; use Tipoff\Forms\Models\ContactResponse; use Tipoff\Forms\Policies\ContactPolicy;