Skip to content

Commit d43026b

Browse files
committed
Fixed what needed fixing and squished some bugs. 🐛
1 parent 98ceebc commit d43026b

20 files changed

+375
-91
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function notes(): MorphMany
3333
{
3434
return $this->morphMany(\Tepuilabs\SimpleCrm\Models\Note::class, 'author');
3535
}
36+
3637
```
3738

3839
## Testing

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: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,74 @@
22

33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

5+
use Illuminate\Database\Eloquent\Model;
6+
use Tepuilabs\SimpleCrm\Models\Enums\LeadStatus;
57
use Illuminate\Database\Eloquent\Factories\Factory;
6-
8+
use Tepuilabs\SimpleCrm\Models\Lead;
79

810
class LeadFactory extends Factory
911
{
1012
/**
1113
* The name of the factory's corresponding model.
1214
*
13-
* @var class-string<\Illuminate\Database\Eloquent\Model>
15+
* @var class-string<Model>
1416
*/
15-
protected $model = \Tepuilabs\SimpleCrm\Models\Lead::class;
16-
17-
const ORGANIC_TYPE = 'Organic';
18-
const USER_SUBMITTED_TYPE = 'User Submitted';
19-
20-
const PROSPECT_STATUS = 'Prospect';
21-
const LEAD_STATUS = 'Lead';
22-
const CUSTOMER_STATUS = 'Customer';
23-
17+
protected $model = Lead::class;
2418

2519
/**
2620
* Define the model's default state.
2721
*
2822
* @return array
2923
*/
30-
public function definition()
24+
public function definition(): array
3125
{
3226
return [
3327
'name' => $this->faker->name,
3428
'email' => $this->faker->email,
35-
'type' => $this->faker->randomElement([self::ORGANIC_TYPE, self::USER_SUBMITTED_TYPE]),
36-
'status' => $this->faker->randomElement([self::PROSPECT_STATUS, self::LEAD_STATUS, self::CUSTOMER_STATUS]),
29+
'type' => $this->faker->randomElement([
30+
LeadStatus::ORGANIC_TYPE(),
31+
LeadStatus::USER_SUBMITTED_TYPE(),
32+
]),
33+
'status' => $this->faker->randomElement([
34+
LeadStatus::PROSPECT_STATUS(),
35+
LeadStatus::LEAD_STATUS(),
36+
LeadStatus::CUSTOMER_STATUS(),
37+
]),
3738
];
3839
}
40+
41+
public function typeOrganic()
42+
{
43+
return $this->state([
44+
'type' => LeadStatus::ORGANIC_TYPE()
45+
]);
46+
}
47+
48+
public function typeUserSubmitted()
49+
{
50+
return $this->state([
51+
'type' => LeadStatus::USER_SUBMITTED_TYPE()
52+
]);
53+
}
54+
55+
public function statusProspect()
56+
{
57+
return $this->state([
58+
'status' => LeadStatus::PROSPECT_STATUS()
59+
]);
60+
}
61+
62+
public function statusLead()
63+
{
64+
return $this->state([
65+
'status' => LeadStatus::LEAD_STATUS()
66+
]);
67+
}
68+
69+
public function statusCustomer()
70+
{
71+
return $this->state([
72+
'status' => LeadStatus::CUSTOMER_STATUS()
73+
]);
74+
}
3975
}

database/factories/NoteFactory.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

55
use Illuminate\Database\Eloquent\Factories\Factory;
6-
6+
use Illuminate\Database\Eloquent\Model;
7+
use Tepuilabs\SimpleCrm\Models\Enums\NoteStatus;
78

89
class NoteFactory extends Factory
910
{
1011
/**
1112
* The name of the factory's corresponding model.
1213
*
13-
* @var class-string<\Illuminate\Database\Eloquent\Model>
14+
* @var class-string<Model>
1415
*/
1516
protected $model = \Tepuilabs\SimpleCrm\Models\Note::class;
1617

17-
const LOW_PRIORITY = 'Low';
18-
const MEDIUM_PRIORITY = 'Medium';
19-
const HIGH_PRIORITY = 'High';
20-
2118

2219
/**
2320
* Define the model's default state.
@@ -30,12 +27,37 @@ public function definition()
3027
$lead = \Tepuilabs\SimpleCrm\Models\Lead::factory()->create();
3128

3229
return [
33-
'priority' => $this->faker->randomElement([self::LOW_PRIORITY, self::MEDIUM_PRIORITY, self::HIGH_PRIORITY]),
34-
'title' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
35-
'body' => $this->faker->paragraphs($nb = 3, $asText = false),
30+
'title' => $this->faker->word,
31+
'body' => $this->faker->paragraphs(),
32+
'priority' => $this->faker->randomElement([
33+
NoteStatus::LOW_PRIORITY(),
34+
NoteStatus::MEDIUM_PRIORITY(),
35+
NoteStatus::HIGH_PRIORITY(),
36+
]),
3637
'lead_id' => $lead->id,
3738
'author_id' => $author->id,
3839
'author_type' => \Tepuilabs\SimpleCrm\Tests\Models\User::class,
3940
];
4041
}
42+
43+
public function priorityLow()
44+
{
45+
return $this->state([
46+
'priority' => NoteStatus::LOW_PRIORITY()
47+
]);
48+
}
49+
50+
public function priorityMedium()
51+
{
52+
return $this->state([
53+
'priority' => NoteStatus::MEDIUM_PRIORITY()
54+
]);
55+
}
56+
57+
public function priorityHigh()
58+
{
59+
return $this->state([
60+
'priority' => NoteStatus::HIGH_PRIORITY()
61+
]);
62+
}
4163
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Tepuilabs\SimpleCrm\Database\Factories;
4+
5+
use Illuminate\Database\Eloquent\Factories\Factory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Tepuilabs\SimpleCrm\Models\Enums\ProjectStatus;
8+
use Tepuilabs\SimpleCrm\Models\Project;
9+
10+
class ProjectFactory extends Factory
11+
{
12+
/**
13+
* The name of the factory's corresponding model.
14+
*
15+
* @var class-string<Model>
16+
*/
17+
protected $model = Project::class;
18+
19+
/**
20+
* Define the model's default state.
21+
*
22+
* @return array
23+
*/
24+
public function definition(): array
25+
{
26+
return [
27+
'title' => $this->faker->jobTitle(),
28+
'description' => $this->faker->paragraphs(),
29+
'deadline' => $this->faker->date(),
30+
'status' => $this->faker->randomElement([
31+
ProjectStatus::OPEN(),
32+
ProjectStatus::CANCELED(),
33+
ProjectStatus::WIP(),
34+
ProjectStatus::BLOCKED(),
35+
ProjectStatus::COMPLETED(),
36+
])
37+
];
38+
}
39+
40+
public function statusOpen()
41+
{
42+
return $this->state([
43+
'status' => ProjectStatus::OPEN()
44+
]);
45+
}
46+
47+
public function statusCanceled()
48+
{
49+
return $this->state([
50+
'status' => ProjectStatus::CANCELED()
51+
]);
52+
}
53+
54+
public function statusWip()
55+
{
56+
return $this->state([
57+
'status' => ProjectStatus::WIP()
58+
]);
59+
}
60+
61+
public function statusBlocked()
62+
{
63+
return $this->state([
64+
'status' => ProjectStatus::BLOCKED()
65+
]);
66+
}
67+
68+
public function statusCompleted()
69+
{
70+
return $this->state([
71+
'status' => ProjectStatus::COMPLETED()
72+
]);
73+
}
74+
}

database/factories/ServiceFactory.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
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\Service;
68

79
class ServiceFactory extends Factory
810
{
911
/**
1012
* The name of the factory's corresponding model.
1113
*
12-
* @var class-string<\Illuminate\Database\Eloquent\Model>
14+
* @var class-string<Model>
1315
*/
14-
protected $model = \Tepuilabs\SimpleCrm\Models\Service::class;
16+
protected $model = Service::class;
1517

1618
/**
1719
* Define the model's default state.
1820
*
1921
* @return array
2022
*/
21-
public function definition()
23+
public function definition(): array
2224
{
2325
return [
24-
'name' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
25-
'description' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
26+
'name' => $this->faker->sentence(),
27+
'description' => $this->faker->sentence(),
2628
'status' => $this->faker->randomElement(['published', 'draft']),
2729
];
2830
}

database/factories/UserFactory.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,34 @@
22

33
namespace Tepuilabs\SimpleCrm\Database\Factories;
44

5+
use Illuminate\Database\Eloquent\Model;
56
use Illuminate\Support\Str;
67
use Illuminate\Database\Eloquent\Factories\Factory;
8+
use Tepuilabs\SimpleCrm\Tests\Models\User;
79

810
class UserFactory extends Factory
911
{
1012
/**
1113
* The name of the factory's corresponding model.
1214
*
13-
* @var class-string<\Illuminate\Database\Eloquent\Model>
15+
* @var class-string<Model>
1416
*/
15-
protected $model = \Tepuilabs\SimpleCrm\Tests\Models\User::class;
17+
protected $model = User::class;
1618

1719

1820
/**
1921
* Define the model's default state.
2022
*
2123
* @return array
2224
*/
23-
public function definition()
25+
public function definition(): array
2426
{
2527
return [
2628
'name' => $this->faker->name,
2729
'email' => $this->faker->unique()->safeEmail,
2830
'email_verified_at' => now(),
2931
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
30-
'remember_token' => Str::random(10),
32+
'remember_token' => Str::random(),
3133
];
3234
}
3335
}

database/migrations/create_notes_table.php.stub

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@ class CreateNotesTable extends Migration
1515
{
1616
Schema::create('notes', function (Blueprint $table) {
1717
$table->id();
18-
$table->text('priority');
1918
$table->text('title');
2019
$table->text('body');
20+
$table->text('priority');
21+
$table->nullableMorphs('commentable');
2122
$table->nullableMorphs('author');
2223
$table->timestamps();
2324
$table->softDeletes();
24-
25-
$table->foreignId('lead_id')
26-
->nullable()
27-
->references('id')
28-
->on('leads');
2925
});
3026
}
3127

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateProjectsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('projects', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('title');
19+
$table->longText('description');
20+
$table->date('deadline');
21+
$table->string('status')->default('open');
22+
$table->timestamps();
23+
$table->softDeletes();
24+
25+
$table->foreignId('lead_id')
26+
->nullable()
27+
->references('id')
28+
->on('leads');
29+
});
30+
}
31+
32+
/**
33+
* Reverse the migrations.
34+
*
35+
* @return void
36+
*/
37+
public function down()
38+
{
39+
Schema::dropIfExists('projects');
40+
}
41+
}

0 commit comments

Comments
 (0)