Skip to content

Commit 2a442ea

Browse files
authored
Merge pull request #35 from tipoff/drewroberts/feature/31-contact-user
Contact User #31
2 parents 9648e92 + d6d1b90 commit 2a442ea

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"dniccum/phone-number": "^1.1",
2020
"inspheric/nova-email-field": "^1.42",
2121
"tipoff/authorization": "^2.5.0",
22-
"tipoff/support": "^1.5.10"
22+
"tipoff/locations": "^2.5.1",
23+
"tipoff/support": "^1.5.0"
2324
},
2425
"require-dev": {
2526
"tipoff/test-support": "^1.2.0"

database/factories/ContactFactory.php

+3-13
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,17 @@
99

1010
class ContactFactory extends Factory
1111
{
12-
/**
13-
* The name of the factory's corresponding model.
14-
*
15-
* @var string
16-
*/
1712
protected $model = Contact::class;
1813

19-
/**
20-
* Define the model's default state.
21-
*
22-
* @return array
23-
*/
2414
public function definition()
2515
{
2616
return [
2717
'form_type' => $this->faker->randomElement(['contact', 'reservation', 'parties', 'groups', 'employment']),
28-
'user_id' => randomOrCreate(app('user')),
2918
'location_id' => randomOrCreate(app('location')),
19+
'email' => $this->faker->email,
20+
'first_name' => $this->faker->firstName,
21+
'last_name' => $this->faker->lastName,
3022
'phone' => '555-555-5555',
31-
'participants' => $this->faker->numberBetween(10, 200),
32-
'requested_date' => $this->faker->dateTimeBetween($startDate = 'now', $endDate = '+6 months')->format('Y-m-d'),
3323
'company_name' => $this->faker->company,
3424
'message' => $this->faker->paragraph,
3525
];

database/migrations/2020_05_20_100000_create_contacts_table.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,25 @@ public function up()
1414
$table->id();
1515
$table->string('form_type')->index(); // String title of the form type so know which one was completed
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.
17-
$table->foreignIdFor(app('user'))->index(); // Will create a user for every form submission, so all need email, first & last name now.
1817
$table->foreignIdFor(app('location'))->index();
18+
$table->string('email');
19+
$table->foreignIdFor(app('user'))->nullable()->index();
20+
$table->string('first_name')->nullable();
21+
$table->string('last_name')->nullable();
22+
$table->string('company_name')->nullable();
1923
$table->string('phone')->nullable(); // Will need to format before saving
24+
$table->text('message')->nullable();
25+
$table->json('additional_fields')->nullable();
26+
27+
// Move application specific data to additonal_fields
2028
$table->smallInteger('participants')->nullable();
2129
$table->date('requested_date')->nullable();
2230
$table->time('requested_time')->nullable(); // Stored in location timezone
23-
$table->string('company_name')->nullable();
24-
$table->text('message')->nullable();
25-
$table->json('additional_fields')->nullable();
31+
32+
// Move response fields to different table (contact followup or something like that)
2633
$table->dateTime('emailed_at')->nullable();
2734
$table->dateTime('closed_at')->nullable();
35+
2836
$table->softDeletes(); // Soft delete if email bounces or if the contact submission is spam.
2937
$table->timestamps();
3038
});

src/Models/Contact.php

-10
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ protected static function boot()
2727

2828
static::creating(function ($contact) {
2929
Assert::lazy()
30-
->that($contact->user_id)->notEmpty('A contact must be made by a user.')
3130
->that($contact->location_id)->notEmpty('A contact must be made to a location.')
3231
->verifyNow();
3332
$contact->generateReferenceNumber();
@@ -48,25 +47,16 @@ public function generateReferenceNumber()
4847
$this->reference_number = $token;
4948
}
5049

51-
/**
52-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
53-
*/
5450
public function user()
5551
{
5652
return $this->belongsTo(app('user'));
5753
}
5854

59-
/**
60-
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
61-
*/
6255
public function location()
6356
{
6457
return $this->belongsTo(app('location'));
6558
}
6659

67-
/**
68-
* @return \Illuminate\Database\Eloquent\Relations\MorphMany
69-
*/
7060
public function notes()
7161
{
7262
return $this->morphMany(app('note'), 'noteable');

tests/TestCase.php

+4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
use Laravel\Nova\NovaCoreServiceProvider;
88
use Spatie\Permission\PermissionServiceProvider;
9+
use Tipoff\Addresses\AddressesServiceProvider;
910
use Tipoff\Authorization\AuthorizationServiceProvider;
1011
use Tipoff\Forms\FormsServiceProvider;
1112
use Tipoff\Forms\Tests\Support\Providers\NovaPackageServiceProvider;
13+
use Tipoff\Locations\LocationsServiceProvider;
1214
use Tipoff\Support\SupportServiceProvider;
1315
use Tipoff\TestSupport\BaseTestCase;
1416

@@ -18,8 +20,10 @@ protected function getPackageProviders($app)
1820
{
1921
return [
2022
SupportServiceProvider::class,
23+
AddressesServiceProvider::class,
2124
AuthorizationServiceProvider::class,
2225
PermissionServiceProvider::class,
26+
LocationsServiceProvider::class,
2327
FormsServiceProvider::class,
2428
NovaCoreServiceProvider::class,
2529
NovaPackageServiceProvider::class,

0 commit comments

Comments
 (0)