Skip to content

Commit 043a6d8

Browse files
committed
🎨 Formatting
1 parent f89fd4f commit 043a6d8

14 files changed

+56
-134
lines changed

Diff for: CONTRIBUTING.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ composer install
1919

2020
As you can see we have:
2121

22+
- `database`: contains the migrations, seeders or factories.
2223
- `src` contains the working code for the repository:
23-
- `database`: contains the migrations, seeders or factories.
2424
- `Facades`: contains the package facades.
2525
- `Helpers`: contains the package helpers.
2626
- `Http`: contains the http utilities like controllers, requests, etc.
27-
- `Traits`: contains the traits to import in the models.
2827

2928
### Issues
3029

Diff for: README.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ In your user model add the `Notifiable` trait. This trait supports custom guards
3535
namespace App;
3636

3737
use Illuminate\Foundation\Auth\User as Authenticatable;
38-
use williamcruzme\NotificationSettings\Traits\Notifiable;
38+
use Millions\Notifications\Notifiable;
3939

4040
class User extends Authenticatable
4141
{
@@ -103,7 +103,7 @@ $user->notify(new InvoicePaid($invoice));
103103
Alternatively, you may send notifications via the `Notification` facade. This is useful primarily when you need to send a notification to multiple notifiable entities such as a collection of users. To send notifications using the facade, pass all of the notifiable entities and the notification instance to the `send` method:
104104

105105
```php
106-
use williamcruzme\NotificationSettings\Facades\Notification;
106+
use Millions\Notifications\Facades\Notification;
107107

108108
Notification::send($users, new InvoicePaid($invoice));
109109
```
@@ -120,7 +120,7 @@ Notification::send($users, new InvoicePaid($invoice));
120120

121121
| Method | URI |
122122
| ------ | --------------------------- |
123-
| PATCH | `/notifications/markAsRead` |
123+
| PATCH | `/notifications/read` |
124124

125125
### Delete notification
126126

@@ -150,12 +150,12 @@ Notification::send($users, new InvoicePaid($invoice));
150150

151151
## 🎨 Customizing
152152

153-
First of all, create your own `NotificationController` `NotificationSettingController` controllers and add the `ManageNotifications` `ManageNotificationSettings` traits.
153+
First of all, create your own `NotificationSettingController` controllers and add the `ManageNotificationSettings` trait.
154154

155155
Second, modify the namespace of the `Notification` facade routes:
156156

157157
```php
158-
Notification::routes('App\Http\Controllers');
158+
Notification::routesForSettings('App\Http\Controllers');
159159
```
160160

161161
### Custom request validations
@@ -167,7 +167,7 @@ The `rules` `validationErrorMessages` methods in the `NotificationSettingControl
167167

168168
namespace App\Http\Controllers;
169169

170-
use williamcruzme\NotificationSettings\Traits\ManageNotificationSettings;
170+
use Millions\Notifications\ManageNotificationSettings;
171171

172172
class NotificationSettingController extends Controller {
173173

@@ -199,18 +199,18 @@ class NotificationSettingController extends Controller {
199199

200200
### Custom response
201201

202-
The `sendResponse` method in the `NotificationController` `NotificationSettingController` allows you override the default response:
202+
The `sendResponse` method in the `NotificationSettingController` allows you override the default response:
203203

204204
```php
205205
<?php
206206

207207
namespace App\Http\Controllers;
208208

209-
use williamcruzme\NotificationSettings\Traits\ManageNotifications;
209+
use Millions\Notifications\ManageNotificationSettings;
210210

211-
class NotificationController extends Controller {
211+
class NotificationSettingController extends Controller {
212212

213-
use ManageNotifications;
213+
use ManageNotificationSettings;
214214

215215
/**
216216
* Get the response for a successful listing notification settings.
@@ -227,18 +227,18 @@ class NotificationController extends Controller {
227227

228228
### Custom guards
229229

230-
The `guard` method in the `NotificationController` `NotificationSettingController` allows you override the default guard:
230+
The `guard` method in the `NotificationSettingController` allows you override the default guard:
231231

232232
```php
233233
<?php
234234

235235
namespace App\Http\Controllers;
236236

237-
use williamcruzme\NotificationSettings\Traits\ManageNotifications;
237+
use Millions\Notifications\ManageNotificationSettings;
238238

239-
class NotificationController extends Controller {
239+
class NotificationSettingController extends Controller {
240240

241-
use ManageNotifications;
241+
use ManageNotificationSettings;
242242

243243
/**
244244
* Get the guard to be used during notifications management.

Diff for: composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@
2525
"extra": {
2626
"laravel": {
2727
"providers": [
28-
"williamcruzme\\NotificationSettings\\NotificationServiceProvider"
28+
"Millions\\Notifications\\NotificationServiceProvider"
2929
],
3030
"aliases": {
31-
"Notification": "williamcruzme\\NotificationSettings\\Facades\\Notification"
31+
"Notification": "Millions\\Notifications\\Facades\\Notification"
3232
}
3333
}
3434
},
3535
"autoload": {
3636
"psr-4": {
37-
"williamcruzme\\NotificationSettings\\": "src/"
37+
"Millions\\Notifications\\": "src/"
3838
}
3939
}
4040
}

Diff for: src/database/migrations/2019_07_12_194431_create_notification_types_table.php renamed to database/migrations/2019_07_12_194431_create_notification_types_table.php

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

3-
use Illuminate\Support\Facades\Schema;
4-
use Illuminate\Database\Schema\Blueprint;
53
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
66

77
class CreateNotificationTypesTable extends Migration
88
{
@@ -15,8 +15,9 @@ public function up()
1515
{
1616
Schema::create('notification_types', function (Blueprint $table) {
1717
$table->bigIncrements('id');
18-
$table->string('name');
18+
$table->string('name')->unique();
1919
$table->string('display_text');
20+
$table->json('schedule')->nullabe();
2021
$table->boolean('status')->default(true);
2122
});
2223
}

Diff for: src/database/migrations/2019_07_15_152649_create_notification_settings_table.php renamed to database/migrations/2019_07_15_152649_create_notification_settings_table.php

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

3-
use Illuminate\Support\Facades\Schema;
4-
use Illuminate\Database\Schema\Blueprint;
53
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
66

77
class CreateNotificationSettingsTable extends Migration
88
{

Diff for: src/Facades/Notification.php

+9-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace williamcruzme\NotificationSettings\Facades;
3+
namespace Millions\Notifications\Facades;
44

5-
use Illuminate\Support\Facades\Route;
65
use Illuminate\Support\Facades\Facade;
6+
use Illuminate\Support\Facades\Route;
77

88
class Notification extends Facade
99
{
@@ -22,21 +22,15 @@ protected static function getFacadeAccessor()
2222
*
2323
* @return void
2424
*/
25-
public static function routes($namespace = '\\williamcruzme\\NotificationSettings\\Http\\Controllers')
25+
public static function routesForSettings($namespace = '\\Millions\\Notifications\\Http\\Controllers')
2626
{
27-
Route::namespace($namespace)->group(function () {
28-
// Notifications
29-
Route::prefix('notifications')->group(function () {
30-
Route::get('/', 'NotificationController@index');
31-
Route::patch('/markAsRead', 'NotificationController@markAsRead');
32-
Route::delete('/', 'NotificationController@destroy');
33-
});
27+
if (! str_starts_with('\\', $namespace)) {
28+
$namespace = "\\$namespace";
29+
}
3430

35-
// Notification Settings
36-
Route::prefix('settings/notifications')->group(function () {
37-
Route::get('/', 'NotificationSettingController@index');
38-
Route::patch('/{notificationType}', 'NotificationSettingController@update');
39-
});
31+
Route::prefix('settings/notifications')->namespace($namespace)->group(function () {
32+
Route::get('/', 'NotificationSettingController@index');
33+
Route::patch('{notificationType}', 'NotificationSettingController@update');
4034
});
4135
}
4236
}

Diff for: src/Helpers/Notification.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace williamcruzme\NotificationSettings\Helpers;
3+
namespace Millions\Notifications\Helpers;
44

55
use Illuminate\Notifications\ChannelManager;
66

Diff for: src/Http/Controllers/NotificationController.php

-11
This file was deleted.

Diff for: src/Http/Controllers/NotificationSettingController.php

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

3-
namespace williamcruzme\NotificationSettings\Http\Controllers;
3+
namespace Millions\Notifications\Http\Controllers;
44

55
use App\Http\Controllers\Controller;
6-
use williamcruzme\NotificationSettings\Traits\ManageNotificationSettings;
6+
use Millions\Notifications\ManageNotificationSettings;
77

88
class NotificationSettingController extends Controller
99
{

Diff for: src/Traits/ManageNotificationSettings.php renamed to src/ManageNotificationSettings.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace williamcruzme\NotificationSettings\Traits;
3+
namespace Millions\Notifications;
44

55
use Illuminate\Http\Request;
6-
use williamcruzme\NotificationSettings\NotificationType;
6+
use Millions\Notifications\NotificationType;
77

88
trait ManageNotificationSettings
99
{
@@ -14,8 +14,8 @@ trait ManageNotificationSettings
1414
*/
1515
public function index()
1616
{
17-
$types = NotificationType::get();
18-
$settings = $this->guard()->user()->notification_settings;
17+
$types = NotificationType::all();
18+
$settings = $this->guard()->user()->notificationSettings;
1919

2020
$types->each(function ($type) use ($settings) {
2121
$setting = $settings->find($type->id);
@@ -29,15 +29,15 @@ public function index()
2929
* Update the specified resource in storage.
3030
*
3131
* @param \Illuminate\Http\Request $request
32-
* @param \williamcruzme\FCM\NotificationType $notificationType
32+
* @param \Millions\Notifications\NotificationType $notificationType
3333
* @return \Illuminate\Http\JsonResponse
3434
*/
3535
public function update(Request $request, NotificationType $notificationType)
3636
{
3737
$request->validate($this->rules(), $this->validationErrorMessages());
3838

39-
$this->guard()->user()->notification_settings()->syncWithoutDetaching([
40-
$notificationType->id => $request->only('status'),
39+
$this->guard()->user()->notificationSettings()->syncWithoutDetaching([
40+
$notificationType->id => $request->boolean('status'),
4141
]);
4242

4343
return response()->json([

Diff for: src/Traits/Notifiable.php renamed to src/Notifiable.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace williamcruzme\NotificationSettings\Traits;
3+
namespace Millions\Notifications;
44

5-
use williamcruzme\NotificationSettings\NotificationType;
65
use Illuminate\Notifications\Notifiable as BaseNotifiable;
6+
use Millions\Notifications\NotificationType;
77

88
trait Notifiable
99
{
@@ -45,7 +45,7 @@ public function notifyNow($instance, array $channels = null)
4545

4646
public function canReceive($notification)
4747
{
48-
$setting = $this->notification_settings()->whereName($notification)->first();
48+
$setting = $this->notificationSettings()->whereName($notification)->first();
4949

5050
// Ensure that user wants recieve the notification
5151
return !$setting || ($setting && $setting->status && $setting->pivot->status);
@@ -56,7 +56,7 @@ public function canReceive($notification)
5656
*
5757
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
5858
*/
59-
public function notification_settings()
59+
public function notificationSettings()
6060
{
6161
return $this
6262
->morphToMany(NotificationType::class, 'user', 'notification_settings')

Diff for: src/NotificationServiceProvider.php

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

3-
namespace williamcruzme\NotificationSettings;
3+
namespace Millions\Notifications;
44

55
use Illuminate\Support\ServiceProvider;
6-
use williamcruzme\NotificationSettings\Helpers\Notification;
6+
use Millions\Notifications\Helpers\Notification;
77

88
class NotificationServiceProvider extends ServiceProvider
99
{
@@ -41,7 +41,7 @@ public function boot()
4141
protected function bootForConsole()
4242
{
4343
$this->publishes([
44-
__DIR__.'/database/migrations' => database_path('migrations')
44+
__DIR__ . '/../database/migrations' => database_path('migrations')
4545
], 'migrations');
4646
}
4747
}

Diff for: src/NotificationType.php

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

3-
namespace williamcruzme\NotificationSettings;
3+
namespace Millions\Notifications;
44

55
use Illuminate\Database\Eloquent\Model;
66

@@ -19,7 +19,10 @@ class NotificationType extends Model
1919
* @var array
2020
*/
2121
protected $fillable = [
22-
'name', 'display_text', 'status',
22+
'name',
23+
'display_text',
24+
'schedule',
25+
'status',
2326
];
2427

2528
/**
@@ -28,6 +31,7 @@ class NotificationType extends Model
2831
* @var array
2932
*/
3033
protected $casts = [
34+
'schedule' => 'array',
3135
'status' => 'boolean',
3236
];
3337
}

0 commit comments

Comments
 (0)