Skip to content

Commit 26cb69f

Browse files
committed
Fixed what needed fixing and squished some bugs. 🐛
1 parent ecaff6d commit 26cb69f

File tree

15 files changed

+253
-114
lines changed

15 files changed

+253
-114
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
}
1616
],
1717
"require": {
18-
"php": "^7.4|^8.0",
18+
"php": "^8.0",
19+
"spatie/laravel-enum": "^3.0",
1920
"spatie/laravel-package-tools": "^1.11"
2021
},
2122
"require-dev": {

database/factories/LeadFactory.php

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,61 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Tepuilabs\SimpleCrm\Models\Enums\Lead\LeadStatus;
7+
use Tepuilabs\SimpleCrm\Models\Enums\Lead\LeadType;
8+
use Tepuilabs\SimpleCrm\Models\Lead;
69

710

811
class LeadFactory extends Factory
912
{
10-
protected $model = \Tepuilabs\SimpleCrm\Models\Lead::class;
11-
12-
const ORGANIC_TYPE = 'Organic';
13-
const USER_SUBMITTED_TYPE = 'User Submitted';
14-
15-
const PROSPECT_STATUS = 'Prospect';
16-
const LEAD_STATUS = 'Lead';
17-
const CUSTOMER_STATUS = 'Customer';
18-
19-
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
protected $model = Lead::class;
17+
18+
/**
19+
* {@inheritdoc}
20+
*/
2021
public function definition()
2122
{
2223
return [
2324
'name' => $this->faker->name,
2425
'email' => $this->faker->email,
25-
'type' => $this->faker->randomElement([self::ORGANIC_TYPE, self::USER_SUBMITTED_TYPE]),
26-
'status' => $this->faker->randomElement([self::PROSPECT_STATUS, self::LEAD_STATUS, self::CUSTOMER_STATUS]),
2726
];
2827
}
28+
29+
public function organicType(): LeadFactory
30+
{
31+
return $this->state([
32+
'type' => LeadType::ORGANIC_TYPE(),
33+
]);
34+
}
35+
36+
public function userSubmittedType(): LeadFactory
37+
{
38+
return $this->state([
39+
'type' => LeadType::USER_SUBMITTED_TYPE(),
40+
]);
41+
}
42+
43+
public function leadStatus(): LeadFactory
44+
{
45+
return $this->state([
46+
'status' => LeadStatus::LEAD_STATUS()
47+
]);
48+
}
49+
50+
public function prospectStatus(): LeadFactory
51+
{
52+
return $this->state([
53+
'status' => LeadStatus::PROSPECT_STATUS()
54+
]);
55+
}
56+
57+
public function customerStatus(): LeadFactory
58+
{
59+
return $this->state([
60+
'status' => LeadStatus::CUSTOMER_STATUS()
61+
]);
62+
}
2963
}

database/factories/NoteFactory.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,52 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Tepuilabs\SimpleCrm\Models\Enums\Note\NotePriority;
7+
use Tepuilabs\SimpleCrm\Models\Note;
68

79

810
class NoteFactory extends Factory
911
{
10-
protected $model = \Tepuilabs\SimpleCrm\Models\Note::class;
11-
12-
const LOW_PRIORITY = 'Low';
13-
const MEDIUM_PRIORITY = 'Medium';
14-
const HIGH_PRIORITY = 'High';
15-
16-
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
protected $model = Note::class;
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
1720
public function definition()
1821
{
19-
$author = \Tepuilabs\SimpleCrm\Tests\Models\User::factory()->create();
20-
$lead = \Tepuilabs\SimpleCrm\Models\Lead::factory()->create();
22+
$author = User::factory()->create();
23+
$lead = Lead::factory()->create();
2124

2225
return [
23-
'priority' => $this->faker->randomElement([self::LOW_PRIORITY, self::MEDIUM_PRIORITY, self::HIGH_PRIORITY]),
2426
'title' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
2527
'body' => $this->faker->paragraphs($nb = 3, $asText = false),
2628
'lead_id' => $lead->id,
2729
'author_id' => $author->id,
2830
'author_type' => \Tepuilabs\SimpleCrm\Tests\Models\User::class,
2931
];
3032
}
33+
34+
public function lowPriority(): NoteFactory
35+
{
36+
return $this->state([
37+
'priority' => NotePriority::LOW_PRIORITY()
38+
]);
39+
}
40+
41+
public function mediumPriority(): NoteFactory
42+
{
43+
return $this->state([
44+
'priority' => NotePriority::MEDIUM_PRIORITY()
45+
]);
46+
}
47+
48+
public function highPriority(): NoteFactory
49+
{
50+
return $this->state([
51+
'priority' => NotePriority::HIGH_PRIORITY()
52+
]);
53+
}
3154
}

database/factories/ServiceFactory.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,29 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Tepuilabs\SimpleCrm\Models\Enums\StatusEnum;
8+
use Tepuilabs\SimpleCrm\Models\Service;
69

710
class ServiceFactory extends Factory
811
{
912
/**
10-
* The name of the factory's corresponding model.
11-
*
12-
* @var string
13+
* {@inheritdoc}
1314
*/
14-
protected $model = \Tepuilabs\SimpleCrm\Models\Service::class;
15+
protected $model = Service::class;
1516

1617
/**
17-
* Define the model's default state.
18-
*
19-
* @return array
18+
* {@inheritdoc}
2019
*/
2120
public function definition()
2221
{
2322
return [
24-
'name' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
25-
'description' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
26-
'status' => $this->faker->randomElement(['published', 'draft']),
23+
'name' => $this->faker->sentence(6, true),
24+
'description' => $this->faker->sentence(6, true),
25+
'status' => $this->faker->randomElement([
26+
StatusEnum::PUBLISHED(),
27+
StatusEnum::DRAFT()
28+
]),
2729
];
2830
}
2931
}

database/migrations/create_services_table.php.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CreateServicesTable extends Migration
1717
$table->id();
1818
$table->string('name')->nullable();
1919
$table->text('description')->nullable();
20-
$table->enum('status', ['published', 'draft'])->default('draft');
20+
$table->enum('status', ['PUBLISHED', 'DRAFT'])->default('DRAFT');
2121
$table->timestamps();
2222
$table->softDeletes();
2323
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Tepuilabs\SimpleCrm\Models\Enums\Lead;
4+
5+
use Spatie\Enum\Laravel\Enum;
6+
7+
/**
8+
* @method static self PROSPECT_STATUS()
9+
* @method static self LEAD_STATUS()
10+
* @method static self CUSTOMER_STATUS()
11+
*/
12+
class LeadStatus extends Enum
13+
{
14+
/**
15+
* @return string
16+
*/
17+
public function label(): string
18+
{
19+
return match ($this->value) {
20+
self::PROSPECT_STATUS()->value => 'prospect',
21+
self::LEAD_STATUS()->value => 'lead',
22+
self::CUSTOMER_STATUS()->value => 'customer',
23+
};
24+
}
25+
}

src/Models/Enums/Lead/LeadType.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Tepuilabs\SimpleCrm\Models\Enums\Lead;
4+
5+
use Spatie\Enum\Laravel\Enum;
6+
7+
/**
8+
* @method static self ORGANIC_TYPE()
9+
* @method static self USER_SUBMITTED_TYPE()
10+
*/
11+
class LeadType extends Enum
12+
{
13+
/**
14+
* @return string
15+
*/
16+
public function label(): string
17+
{
18+
return match ($this->value) {
19+
self::ORGANIC_TYPE()->value => 'organic',
20+
self::USER_SUBMITTED_TYPE()->value => 'user submitted',
21+
};
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
namespace Tepuilabs\SimpleCrm\Models\Enums\Note;
3+
4+
use Spatie\Enum\Laravel\Enum;
5+
6+
/**
7+
* @method static self LOW_PRIORITY()
8+
* @method static self MEDIUM_PRIORITY()
9+
* @method static self HIGH_PRIORITY()
10+
*/
11+
class NotePriority extends Enum
12+
{
13+
/**
14+
* @return string
15+
*/
16+
public function label(): string
17+
{
18+
return match ($this->value) {
19+
self::LOW_PRIORITY()->value => 'low',
20+
self::MEDIUM_PRIORITY()->value => 'medium',
21+
self::HIGH_PRIORITY()->value => 'high',
22+
};
23+
}
24+
}

src/Models/Enums/StatusEnum.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Tepuilabs\SimpleCrm\Models\Enums;
4+
5+
use Spatie\Enum\Laravel\Enum;
6+
7+
/**
8+
* @method static self DRAFT()
9+
* @method static self PUBLISHED()
10+
*/
11+
class StatusEnum extends Enum
12+
{
13+
/**
14+
* @return string
15+
*/
16+
public function label(): string
17+
{
18+
return match ($this->value) {
19+
self::DRAFT()->value => 'DRAFT',
20+
self::PUBLISHED()->value => 'PUBLISHED',
21+
};
22+
}
23+
}

src/Models/Lead.php

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;
77
use Illuminate\Database\Eloquent\Relations\HasMany;
8+
use Tepuilabs\SimpleCrm\Models\Enums\Lead\LeadStatus;
9+
use Tepuilabs\SimpleCrm\Models\Enums\Lead\LeadType;
810

911
/**
1012
* @url https://www.hipb2b.com/blog/lead-prospect-whats-difference
@@ -13,17 +15,8 @@ class Lead extends Model
1315
{
1416
use HasFactory;
1517

16-
const ORGANIC_TYPE = 'Organic';
17-
const USER_SUBMITTED_TYPE = 'User Submitted';
18-
19-
const PROSPECT_STATUS = 'Prospect';
20-
const LEAD_STATUS = 'Lead';
21-
const CUSTOMER_STATUS = 'Customer';
22-
2318
/**
24-
* The attributes that are mass assignable.
25-
*
26-
* @var array
19+
* {@inheritdoc}
2720
*/
2821
protected $fillable = [
2922
'name',
@@ -33,39 +26,20 @@ class Lead extends Model
3326
];
3427

3528
/**
36-
* Notes relationship
37-
*
38-
* @return HasMany
29+
* {@inheritdoc}
3930
*/
40-
public function notes(): HasMany
41-
{
42-
return $this->hasMany(\App\Models\Tepuilabs\SimpleCrm\Note::class);
43-
}
44-
45-
/**
46-
* Undocumented function
47-
*
48-
* @return array
49-
*/
50-
public static function getTypes(): array
51-
{
52-
return [
53-
self::ORGANIC_TYPE => self::ORGANIC_TYPE,
54-
self::USER_SUBMITTED_TYPE => self::USER_SUBMITTED_TYPE,
55-
];
56-
}
31+
protected $casts = [
32+
'status' => LeadStatus::class,
33+
'type' => LeadType::class,
34+
];
5735

5836
/**
59-
* Undocumented function
37+
* Notes relationship
6038
*
61-
* @return array
39+
* @return HasMany
6240
*/
63-
public static function getStatuses(): array
41+
public function notes(): HasMany
6442
{
65-
return [
66-
self::PROSPECT_STATUS => self::PROSPECT_STATUS,
67-
self::LEAD_STATUS => self::LEAD_STATUS,
68-
self::CUSTOMER_STATUS => self::CUSTOMER_STATUS,
69-
];
43+
return $this->hasMany(Note::class);
7044
}
7145
}

0 commit comments

Comments
 (0)