Skip to content

Commit 7f954ad

Browse files
committed
Update Email address relationship #46
1 parent 1bec514 commit 7f954ad

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

database/factories/ContactFactory.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ class ContactFactory extends Factory
1515
public function definition()
1616
{
1717
return [
18-
'form_type' => $this->faker->randomElement(FormType::getValues()),
19-
'location_id' => randomOrCreate(app('location')),
20-
'email' => $this->faker->email,
21-
'first_name' => $this->faker->firstName,
22-
'last_name' => $this->faker->lastName,
23-
'phone' => '555-555-5555',
24-
'company_name' => $this->faker->company,
25-
'message' => $this->faker->paragraph,
18+
'form_type' => $this->faker->randomElement(FormType::getValues()),
19+
'location_id' => randomOrCreate(app('location')),
20+
'email_address_id' => randomOrCreate(app('email_address')),
21+
'first_name' => $this->faker->firstName,
22+
'last_name' => $this->faker->lastName,
23+
'phone' => '555-555-5555',
24+
'company_name' => $this->faker->company,
25+
'message' => $this->faker->paragraph,
2626
];
2727
}
2828
}

database/migrations/2020_05_20_100000_create_contacts_table.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function up()
1515
$table->string('form_type')->index();
1616
$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.
1717
$table->foreignIdFor(app('location'))->index();
18-
$table->string('email');
18+
$table->foreignIdFor(app('email_address'))->index();
1919
$table->foreignIdFor(app('user'))->nullable()->index();
2020
$table->string('first_name')->nullable();
2121
$table->string('last_name')->nullable();

src/Models/Contact.php

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public function getContactStatusHistory(): Collection
7777
return $this->getStatusHistory(ContactStatus::statusType());
7878
}
7979

80+
public function email()
81+
{
82+
return $this->hasOne(app('email_address'));
83+
}
84+
8085
public function response()
8186
{
8287
return $this->hasOne(ContactResponse::class);

src/Nova/Contact.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function fields(Request $request)
7171
nova('location') ? BelongsTo::make('Location', 'location', nova('location'))->required()->hideWhenUpdating() : null,
7272
nova('user') ? BelongsTo::make('User', 'user', nova('user'))->required()->hideWhenUpdating() : null,
7373
PhoneNumber::make('Phone')->format('###-###-####')->disableValidation()->useMaskPlaceholder()->linkOnDetail()->hideWhenUpdating(),
74-
Email::make('Email', 'user.email')->clickable()->hideWhenUpdating(),
74+
nova('email_address') ? BelongsTo::make('Email Address', 'email_address', nova('email_address'))->sortable() : null,
7575
Textarea::make('Message')->rows(3)->alwaysShow()->nullable()->hideWhenUpdating(),
7676

7777
new Panel('Submission Details', $this->submissionFields()),

0 commit comments

Comments
 (0)