Skip to content

Commit 666da62

Browse files
author
angel cruz
committed
Fixed what needed fixing and squished some bugs. 🐛
1 parent 31c6995 commit 666da62

File tree

12 files changed

+144
-21
lines changed

12 files changed

+144
-21
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ php artisan vendor:publish --provider="Tepuilabs\SimpleCrm\SimpleCrmServiceProvi
2424
php artisan migrate
2525
```
2626

27+
## Usage
28+
29+
This package uses a polymorphic relationship to associate the Items model with the model of your choice, the only thing you have to do is add this to the model you want to use:
30+
31+
```php
32+
public function notes()
33+
{
34+
return $this->morphMany(Note::class, 'author');
35+
}
36+
```
37+
2738
## Testing
2839

2940
```bash

database/factories/LeadFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class LeadFactory extends Factory
99
{
10-
protected $model = \Tepuilabs\SimpleCrm\Models\Lead::class;
10+
protected $model = \Tepuilabs\SimpleCrm\Tests\Models\Lead::class;
1111

1212
const ORGANIC_TYPE = 'Organic';
1313
const USER_SUBMITTED_TYPE = 'User Submitted';

database/factories/NoteFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class NoteFactory extends Factory
99
{
10-
protected $model = \Tepuilabs\SimpleCrm\Models\Note::class;
10+
protected $model = \Tepuilabs\SimpleCrm\Tests\Models\Note::class;
1111

1212
const LOW_PRIORITY = 'Low';
1313
const MEDIUM_PRIORITY = 'Medium';
@@ -17,7 +17,7 @@ class NoteFactory extends Factory
1717
public function definition()
1818
{
1919
$author = \Tepuilabs\SimpleCrm\Tests\Models\User::factory()->create();
20-
$lead = \Tepuilabs\SimpleCrm\Models\Lead::factory()->create();
20+
$lead = \Tepuilabs\SimpleCrm\Tests\Models\Lead::factory()->create();
2121

2222
return [
2323
'priority' => $this->faker->randomElement([self::LOW_PRIORITY, self::MEDIUM_PRIORITY, self::HIGH_PRIORITY]),

src/Models/Lead.php renamed to models/Lead.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tepuilabs\SimpleCrm\Models;
3+
namespace Tepuilabs\SimpleCrm;
44

55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;

src/Models/Note.php renamed to models/Note.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Tepuilabs\SimpleCrm\Models;
3+
namespace Tepuilabs\SimpleCrm;
44

55
use Illuminate\Database\Eloquent\Factories\HasFactory;
66
use Illuminate\Database\Eloquent\Model;

src/SimpleCrmServiceProvider.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class SimpleCrmServiceProvider extends ServiceProvider
99
public function boot(): void
1010
{
1111
if ($this->app->runningInConsole()) {
12+
$this->publishes([
13+
__DIR__ . '/../models' => base_path('Tepuilabs/SimpleCrm'),
14+
], 'models');
15+
1216
$migrationFileNames = [
1317
'create_leads_table.php',
1418
'create_notes_table.php',

src/Traits/HasNote.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/Models/Lead.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
namespace Tepuilabs\SimpleCrm\Tests\Models;
3+
4+
use Illuminate\Database\Eloquent\Factories\HasFactory;
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\HasMany;
7+
8+
/**
9+
* @url https://www.hipb2b.com/blog/lead-prospect-whats-difference
10+
*/
11+
class Lead extends Model
12+
{
13+
use HasFactory;
14+
15+
const ORGANIC_TYPE = 'Organic';
16+
const USER_SUBMITTED_TYPE = 'User Submitted';
17+
18+
const PROSPECT_STATUS = 'Prospect';
19+
const LEAD_STATUS = 'Lead';
20+
const CUSTOMER_STATUS = 'Customer';
21+
22+
/**
23+
* The attributes that are mass assignable.
24+
*
25+
* @var array
26+
*/
27+
protected $fillable = [
28+
'name',
29+
'email',
30+
'type',
31+
'status',
32+
];
33+
34+
/**
35+
* Notes relationship
36+
*
37+
* @return HasMany
38+
*/
39+
public function notes(): HasMany
40+
{
41+
return $this->hasMany(\Tepuilabs\SimpleCrm\Models\Note::class);
42+
}
43+
44+
/**
45+
* Undocumented function
46+
*
47+
* @return array
48+
*/
49+
public static function getTypes(): array
50+
{
51+
return [
52+
self::ORGANIC_TYPE => self::ORGANIC_TYPE,
53+
self::USER_SUBMITTED_TYPE => self::USER_SUBMITTED_TYPE,
54+
];
55+
}
56+
57+
/**
58+
* Undocumented function
59+
*
60+
* @return array
61+
*/
62+
public static function getStatuses(): array
63+
{
64+
return [
65+
self::PROSPECT_STATUS => self::PROSPECT_STATUS,
66+
self::LEAD_STATUS => self::LEAD_STATUS,
67+
self::CUSTOMER_STATUS => self::CUSTOMER_STATUS,
68+
];
69+
}
70+
}

tests/Models/Note.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
namespace Tepuilabs\SimpleCrm\Tests\Models;
3+
4+
use Illuminate\Database\Eloquent\Factories\HasFactory;
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7+
use Illuminate\Database\Eloquent\Relations\MorphTo;
8+
9+
class Note extends Model
10+
{
11+
use HasFactory;
12+
13+
const LOW_PRIORITY = 'Low';
14+
const MEDIUM_PRIORITY = 'Medium';
15+
const HIGH_PRIORITY = 'High';
16+
17+
/**
18+
* The attributes that are mass assignable.
19+
*
20+
* @var array
21+
*/
22+
protected $fillable = [
23+
'priority',
24+
'title',
25+
'body',
26+
];
27+
28+
public function author(): MorphTo
29+
{
30+
return $this->morphTo();
31+
}
32+
33+
public function lead(): BelongsTo
34+
{
35+
return $this->belongsTo(\Tepuilabs\SimpleCrm\Models\Lead::class);
36+
}
37+
38+
public static function getPriorities(): array
39+
{
40+
return [
41+
self::LOW_PRIORITY => self::LOW_PRIORITY,
42+
self::MEDIUM_PRIORITY => self::MEDIUM_PRIORITY,
43+
self::HIGH_PRIORITY => self::HIGH_PRIORITY,
44+
];
45+
}
46+
}

tests/Models/User.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
use Illuminate\Database\Eloquent\Factories\HasFactory;
55
use Illuminate\Foundation\Auth\User as Authenticatable;
66
use Illuminate\Notifications\Notifiable;
7-
use Tepuilabs\SimpleCrm\Traits\HasNote;
87

98
class User extends Authenticatable
109
{
1110
use HasFactory;
1211
use Notifiable;
13-
use HasNote;
1412

1513
/**
1614
* The attributes that are mass assignable.
@@ -41,4 +39,9 @@ class User extends Authenticatable
4139
protected $casts = [
4240
'email_verified_at' => 'datetime',
4341
];
42+
43+
public function notes()
44+
{
45+
return $this->morphMany(\Tepuilabs\SimpleCrm\Tests\Models\Note::class, 'author');
46+
}
4447
}

0 commit comments

Comments
 (0)