Skip to content

Commit b14be7a

Browse files
committed
Update migrations #30
1 parent accd379 commit b14be7a

5 files changed

+53
-15
lines changed

database/migrations/2020_05_20_100000_create_contacts_table.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function up()
1212
{
1313
Schema::create('contacts', function (Blueprint $table) {
1414
$table->id();
15-
$table->string('form_type')->index(); // String title of the form type so know which one was completed
15+
$table->string('form_type')->index(); // Todo: Change this to enum?
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();
1818
$table->string('email');
@@ -22,17 +22,8 @@ public function up()
2222
$table->string('company_name')->nullable();
2323
$table->string('phone')->nullable(); // Will need to format before saving
2424
$table->text('message')->nullable();
25-
$table->json('additional_fields')->nullable();
26-
27-
// Move application specific data to additonal_fields
28-
$table->smallInteger('participants')->nullable();
29-
$table->date('requested_date')->nullable();
30-
$table->time('requested_time')->nullable(); // Stored in location timezone
31-
32-
// Move response fields to different table (contact followup or something like that)
33-
$table->dateTime('emailed_at')->nullable();
34-
$table->dateTime('closed_at')->nullable();
35-
25+
$table->json('fields')->nullable();
26+
3627
$table->softDeletes(); // Soft delete if email bounces or if the contact submission is spam.
3728
$table->timestamps();
3829
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Illuminate\Database\Migrations\Migration;
6+
use Illuminate\Database\Schema\Blueprint;
7+
use Illuminate\Support\Facades\Schema;
8+
use Tipoff\Forms\Models\Contact;
9+
10+
class CreateContactFollowupsTable extends Migration
11+
{
12+
public function up()
13+
{
14+
Schema::create('contact_followups', function (Blueprint $table) {
15+
$table->id();
16+
$table->foreignIdFor(Contact::class);
17+
$table->dateTime('emailed_at')->nullable();
18+
$table->dateTime('closed_at')->nullable();
19+
});
20+
}
21+
}

src/Models/Contact.php

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Contact extends BaseModel
2424
protected $casts = [
2525
'emailed_at' => 'datetime',
2626
'requested_date' => 'date',
27+
'fields' => 'array',
2728
];
2829

2930
protected static function boot()
@@ -76,6 +77,11 @@ public function getContactStatusHistory(): Collection
7677
return $this->getStatusHistory(ContactStatus::statusType());
7778
}
7879

80+
public function followup()
81+
{
82+
return $this->hasOne(ContactFollowup::class);
83+
}
84+
7985
public function user()
8086
{
8187
return $this->belongsTo(app('user'));

src/Models/ContactFollowup.php

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tipoff\Forms\Models;
6+
7+
use Illuminate\Database\Eloquent\SoftDeletes;
8+
use Tipoff\Support\Models\BaseModel;
9+
use Tipoff\Support\Traits\HasPackageFactory;
10+
11+
class ContactFollowup extends BaseModel
12+
{
13+
use HasPackageFactory;
14+
use SoftDeletes;
15+
16+
public function contact()
17+
{
18+
return $this->belongsTo(Contact::class);
19+
}
20+
}

src/Nova/Contact.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ protected function submissionFields()
8383
{
8484
return [
8585
Text::make('Number', 'reference_number')->exceptOnForms(),
86-
Number::make('Participants')->nullable()->hideWhenUpdating(),
87-
Date::make('Requested Date')->nullable()->hideWhenUpdating(),
88-
Text::make('Requested Time')->nullable()->hideWhenUpdating(),
86+
Number::make('Participants', 'fields->participants')->nullable()->hideWhenUpdating(),
87+
Date::make('Requested Date', 'fields->requested_date')->nullable()->hideWhenUpdating(),
88+
Text::make('Requested Time', 'fields->requested_time')->nullable()->hideWhenUpdating(),
8989
Text::make('Company Name')->nullable()->hideWhenUpdating(),
9090
];
9191
}

0 commit comments

Comments
 (0)