Skip to content

Commit 579e593

Browse files
committed
Spatie config
1 parent 794b1dc commit 579e593

File tree

11 files changed

+513
-61
lines changed

11 files changed

+513
-61
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
### Fixed
2121
### Removed --->
2222

23+
## 0.9.0 - 2021-11-02
24+
### Added
25+
- Model audit logging
26+
- Config for spatie permissions
27+
### Fixed
28+
- Address types teams support
29+
2330
## 0.8.1 - 2021-10-28
2431
### Fixed
2532
- Editing roles in teams mode

README.md

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1946e83f51de4a0eb430a8e0a1aab3cf)](https://app.codacy.com/gh/venturedrake/laravel-crm?utm_source=github.com&utm_medium=referral&utm_content=venturedrake/laravel-crm&utm_campaign=Badge_Grade_Settings)
77
[![Total Downloads](https://img.shields.io/packagist/dt/venturedrake/laravel-crm.svg?style=flat-square)](https://packagist.org/packages/venturedrake/laravel-crm)
88

9-
This package will add CRM functionality to your laravel projects
9+
The free CRM you have been looking for, this package will add CRM functionality to your laravel projects or can be used as a complete standalone CRM built with Laravel.
1010

1111
> ⚠️ Warning: This is a pre-release version that is not recommended for production use.
1212
@@ -24,12 +24,12 @@ This package will add CRM functionality to your laravel projects
2424
- Sales leads management
2525
- Deal management
2626
- Contact database management
27-
- Products
27+
- Products & Product Categories
2828
- Users & Teams
2929
- Secure registration & login
30-
- Reset forgotten password
3130
- Laravel Jetstream/Spark teams support
32-
- Team level roles & permissions
31+
- Roles & Permissions thanks to [Spatie Permissions](https://github.com/spatie/laravel-permission)
32+
- Model Audit logging thanks to [Laravel Auditing](https://github.com/owen-it/laravel-auditing)
3333

3434
## Requirements
3535

@@ -51,32 +51,18 @@ https://laravel.com/docs/6.x/authentication
5151
#### Step 3. Require the current package using composer:
5252

5353
```bash
54-
composer require venturedrake/laravel-crm:^0.8
54+
composer require venturedrake/laravel-crm:^0.9
5555
```
5656

57-
#### Step 4. Install spatie roles & permissions package
58-
59-
https://spatie.be/docs/laravel-permission/v4/installation-laravel
60-
61-
Adjust the settings in app/config/permission.php to the following:
62-
63-
```php
64-
'permission' => VentureDrake\LaravelCrm\Models\Permission::class
65-
'role' => VentureDrake\LaravelCrm\Models\Role::class,
66-
```
67-
68-
If you are using the teams feature, follow this additional step:
69-
https://spatie.be/docs/laravel-permission/v5/basic-usage/teams-permissions
70-
71-
#### Step 5. Publish the migrations, config & assets
57+
#### Step 4. Publish the migrations, config & assets
7258

7359
```bash
7460
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="migrations"
7561
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="config"
7662
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="assets" --force
7763
```
7864

79-
#### Step 6. Update the various config settings in the published config file:
65+
#### Step 5. Update the various config settings in the published config file:
8066

8167
After publishing the package assets a configuration file will be located at <code>config/laravel-crm.php</code>
8268

@@ -110,19 +96,19 @@ Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
11096
})->name('dashboard');
11197
```
11298

113-
#### Step 7. Run migrations:
99+
#### Step 6. Run migrations:
114100

115101
```bash
116102
php artisan migrate
117103
```
118104

119-
#### Step 8. Run database seeder:
105+
#### Step 7. Run database seeder:
120106

121107
```bash
122108
php artisan db:seed --class="VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmTablesSeeder"
123109
```
124110

125-
#### Step 9. Add the HasCrmAccess, HasCrmTeams & HasRoles traits to your User model(s):
111+
#### Step 8. Add the HasCrmAccess, HasCrmTeams & HasRoles traits to your User model(s):
126112

127113
```php
128114
use Illuminate\Foundation\Auth\User as Authenticatable;
@@ -139,7 +125,7 @@ class User extends Authenticatable
139125
// ...
140126
}
141127
```
142-
#### Step 10. Register at least one user and log in or if you already have a user login with the crm owner you set in step 5
128+
#### Step 9. Register at least one user and log in or if you already have a user login with the crm owner you set in step 5
143129

144130
Access the crm to register/login at http://your-project-url/crm
145131

@@ -152,8 +138,9 @@ Note if you modified the route_prefix setting from the default the above url wil
152138
#### Step 1. Run the following to the update migrations and publish assets:
153139

154140
```bash
155-
composer require venturedrake/laravel-crm::^0.6
141+
composer require venturedrake/laravel-crm::^0.9
156142
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="migrations"
143+
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="config"
157144
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="assets" --force
158145
php artisan migrate
159146
```
@@ -169,23 +156,17 @@ php artisan db:seed --class="VentureDrake\LaravelCrm\Database\Seeders\LaravelCrm
169156
#### Step 1. Run the following to the update package:
170157

171158
```bash
172-
composer require venturedrake/laravel-crm:^0.6
173-
```
174-
175-
#### Step 2. Delete previously published package views located in <code>resources/views/vendor/laravel-crm/*</code>
176-
177-
#### Step 3. Install and set up spatie roles & permissions package, see install step 3.
178-
179-
#### Step 4. Add HasCrmAccess, HasCrmTeams & HasRoles traits to App\User model, see installation Step 8.
180-
181-
#### Step 5. Run the following to the update database and add the default roles/permissions:
182-
```bash
159+
composer require venturedrake/laravel-crm::^0.9
183160
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="migrations"
161+
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="config"
184162
php artisan vendor:publish --provider="VentureDrake\LaravelCrm\LaravelCrmServiceProvider" --tag="assets" --force
185163
php artisan migrate
186-
php artisan db:seed --class="VentureDrake\LaravelCrm\Database\Seeders\LaravelCrmTablesSeeder"
187164
```
188165

166+
#### Step 2. Delete previously published package views located in <code>resources/views/vendor/laravel-crm/*</code>
167+
168+
#### Step 3. Add HasCrmAccess, HasCrmTeams & HasRoles traits to App\User model, see installation Step 8.
169+
189170
<!--- ## Usage --->
190171

191172
## Testing

config/package.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
|
1414
*/
1515

16-
'version' => '0.8.1',
16+
'version' => '0.9.0',
1717

1818
];

config/permission.php

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
return [
4+
5+
'models' => [
6+
7+
/*
8+
* When using the "HasPermissions" trait from this package, we need to know which
9+
* Eloquent model should be used to retrieve your permissions. Of course, it
10+
* is often just the "Permission" model but you may use whatever you like.
11+
*
12+
* The model you want to use as a Permission model needs to implement the
13+
* `Spatie\Permission\Contracts\Permission` contract.
14+
*/
15+
16+
'permission' => VentureDrake\LaravelCrm\Models\Permission::class,
17+
18+
/*
19+
* When using the "HasRoles" trait from this package, we need to know which
20+
* Eloquent model should be used to retrieve your roles. Of course, it
21+
* is often just the "Role" model but you may use whatever you like.
22+
*
23+
* The model you want to use as a Role model needs to implement the
24+
* `Spatie\Permission\Contracts\Role` contract.
25+
*/
26+
27+
'role' => VentureDrake\LaravelCrm\Models\Role::class,
28+
29+
],
30+
31+
'table_names' => [
32+
33+
/*
34+
* When using the "HasRoles" trait from this package, we need to know which
35+
* table should be used to retrieve your roles. We have chosen a basic
36+
* default value but you may easily change it to any table you like.
37+
*/
38+
39+
'roles' => 'roles',
40+
41+
/*
42+
* When using the "HasPermissions" trait from this package, we need to know which
43+
* table should be used to retrieve your permissions. We have chosen a basic
44+
* default value but you may easily change it to any table you like.
45+
*/
46+
47+
'permissions' => 'permissions',
48+
49+
/*
50+
* When using the "HasPermissions" trait from this package, we need to know which
51+
* table should be used to retrieve your models permissions. We have chosen a
52+
* basic default value but you may easily change it to any table you like.
53+
*/
54+
55+
'model_has_permissions' => 'model_has_permissions',
56+
57+
/*
58+
* When using the "HasRoles" trait from this package, we need to know which
59+
* table should be used to retrieve your models roles. We have chosen a
60+
* basic default value but you may easily change it to any table you like.
61+
*/
62+
63+
'model_has_roles' => 'model_has_roles',
64+
65+
/*
66+
* When using the "HasRoles" trait from this package, we need to know which
67+
* table should be used to retrieve your roles permissions. We have chosen a
68+
* basic default value but you may easily change it to any table you like.
69+
*/
70+
71+
'role_has_permissions' => 'role_has_permissions',
72+
],
73+
74+
'column_names' => [
75+
/*
76+
* Change this if you want to name the related pivots other than defaults
77+
*/
78+
'role_pivot_key' => null, //default 'role_id',
79+
'permission_pivot_key' => null, //default 'permission_id',
80+
81+
/*
82+
* Change this if you want to name the related model primary key other than
83+
* `model_id`.
84+
*
85+
* For example, this would be nice if your primary keys are all UUIDs. In
86+
* that case, name this `model_uuid`.
87+
*/
88+
89+
'model_morph_key' => 'model_id',
90+
91+
/*
92+
* Change this if you want to use the teams feature and your related model's
93+
* foreign key is other than `team_id`.
94+
*/
95+
96+
'team_foreign_key' => 'team_id',
97+
],
98+
99+
/*
100+
* When set to true the package implements teams using the 'team_foreign_key'. If you want
101+
* the migrations to register the 'team_foreign_key', you must set this to true
102+
* before doing the migration. If you already did the migration then you must make a new
103+
* migration to also add 'team_foreign_key' to 'roles', 'model_has_roles', and
104+
* 'model_has_permissions'(view the latest version of package's migration file)
105+
*/
106+
107+
'teams' => true,
108+
109+
/*
110+
* When set to true, the required permission names are added to the exception
111+
* message. This could be considered an information leak in some contexts, so
112+
* the default setting is false here for optimum safety.
113+
*/
114+
115+
'display_permission_in_exception' => false,
116+
117+
/*
118+
* When set to true, the required role names are added to the exception
119+
* message. This could be considered an information leak in some contexts, so
120+
* the default setting is false here for optimum safety.
121+
*/
122+
123+
'display_role_in_exception' => false,
124+
125+
/*
126+
* By default wildcard permission lookups are disabled.
127+
*/
128+
129+
'enable_wildcard_permission' => false,
130+
131+
'cache' => [
132+
133+
/*
134+
* By default all permissions are cached for 24 hours to speed up performance.
135+
* When permissions or roles are updated the cache is flushed automatically.
136+
*/
137+
138+
'expiration_time' => \DateInterval::createFromDateString('24 hours'),
139+
140+
/*
141+
* The cache key used to store all permissions.
142+
*/
143+
144+
'key' => 'spatie.permission.cache',
145+
146+
/*
147+
* You may optionally indicate a specific cache driver to use for permission and
148+
* role caching using any of the `store` drivers listed in the cache.php config
149+
* file. Using 'default' here means to use the `default` set in cache.php.
150+
*/
151+
152+
'store' => 'default',
153+
],
154+
];
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class AddTeamsFields extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
$teams = config('permission.teams');
17+
$tableNames = config('permission.table_names');
18+
$columnNames = config('permission.column_names');
19+
20+
if (! $teams) {
21+
return;
22+
}
23+
if (empty($tableNames)) {
24+
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
25+
}
26+
if (empty($columnNames['team_foreign_key'] ?? null)) {
27+
throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
28+
}
29+
30+
Schema::table($tableNames['roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
31+
if (! Schema::hasColumn($tableNames['roles'], $columnNames['team_foreign_key'])) {
32+
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
33+
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
34+
}
35+
});
36+
37+
Schema::table($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) {
38+
if (! Schema::hasColumn($tableNames['model_has_permissions'], $columnNames['team_foreign_key'])) {
39+
$table->unsignedBigInteger($columnNames['team_foreign_key'])->default('1');;
40+
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
41+
42+
$table->dropPrimary();
43+
$table->primary([$columnNames['team_foreign_key'], 'permission_id', $columnNames['model_morph_key'], 'model_type'],
44+
'model_has_permissions_permission_model_type_primary');
45+
}
46+
});
47+
48+
Schema::table($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
49+
if (! Schema::hasColumn($tableNames['model_has_roles'], $columnNames['team_foreign_key'])) {
50+
$table->unsignedBigInteger($columnNames['team_foreign_key'])->default('1');;
51+
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
52+
53+
$table->dropPrimary();
54+
$table->primary([$columnNames['team_foreign_key'], 'role_id', $columnNames['model_morph_key'], 'model_type'],
55+
'model_has_roles_role_model_type_primary');
56+
}
57+
});
58+
59+
app('cache')
60+
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
61+
->forget(config('permission.cache.key'));
62+
}
63+
64+
/**
65+
* Reverse the migrations.
66+
*
67+
* @return void
68+
*/
69+
public function down()
70+
{
71+
72+
}
73+
}

0 commit comments

Comments
 (0)