Skip to content

Commit 946bb7c

Browse files
committed
Use Enum for Form Type #30
1 parent b14be7a commit 946bb7c

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

database/factories/ContactFactory.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<?php
1+
<?php
22

33
declare(strict_types=1);
44

55
namespace Tipoff\Forms\Database\Factories;
66

77
use Illuminate\Database\Eloquent\Factories\Factory;
8+
use Tipoff\Forms\Enums\FormType;
89
use Tipoff\Forms\Models\Contact;
910

1011
class ContactFactory extends Factory
@@ -14,7 +15,7 @@ class ContactFactory extends Factory
1415
public function definition()
1516
{
1617
return [
17-
'form_type' => $this->faker->randomElement(['contact', 'reservation', 'parties', 'groups', 'employment']),
18+
'form_type' => $this->faker->randomElement(FormType::getValues()),
1819
'location_id' => randomOrCreate(app('location')),
1920
'email' => $this->faker->email,
2021
'first_name' => $this->faker->firstName,

database/migrations/2020_05_20_100000_create_contacts_table.php

+1-1
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(); // Todo: Change this to enum?
15+
$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();
1818
$table->string('email');

src/Enums/FormType.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tipoff\Forms\Enums;
6+
7+
use MabeEnum\Enum;
8+
9+
/**
10+
* @method static FormType CONTACT()
11+
* @method static FormType EMPLOYMENT()
12+
* @method static FormType GROUPS()
13+
* @method static FormType PARTIES()
14+
* @method static FormType RESERVATIONS()
15+
* @psalm-immutable
16+
*/
17+
class FormType extends Enum
18+
{
19+
const CONTACT = 'contact';
20+
const EMPLOYMENT = 'employment';
21+
const GROUPS = 'groups';
22+
const PARTIES = 'parties';
23+
const RESERVATIONS = 'reservations';
24+
}

src/Nova/Contact.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Laravel\Nova\Http\Requests\NovaRequest;
1919
use Laravel\Nova\Panel;
2020
use Tipoff\Forms\Enums\ContactStatus;
21+
use Tipoff\Forms\Enums\FormType;
2122
use Tipoff\Support\Nova\BaseResource;
2223
use Tipoff\Support\Nova\Fields\Enum;
2324

@@ -61,11 +62,11 @@ public function fields(Request $request)
6162
return $contact->getContactStatus();
6263
})->attach(ContactStatus::class),
6364
Select::make('Form Type')->options([
64-
'contact' => 'Contact Page',
65-
'reservation' => 'Reservation Page',
66-
'parties' => 'Private Parties Page',
67-
'groups' => 'Team Building Page',
68-
'employment' => 'Employment Page',
65+
FormType::CONTACT => 'Contact',
66+
FormType::RESERVATIONS => 'Reservations',
67+
FormType::PARTIES => 'Parties',
68+
FormType::GROUPS => 'Groups',
69+
FormType::EMPLOYMENT => 'Employment',
6970
])->required()->hideWhenUpdating(),
7071
nova('location') ? BelongsTo::make('Location', 'location', nova('location'))->required()->hideWhenUpdating() : null,
7172
nova('user') ? BelongsTo::make('User', 'user', nova('user'))->required()->hideWhenUpdating() : null,

0 commit comments

Comments
 (0)