1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Adminetic\Announcement\Provider; |
4
|
|
|
|
5
|
|
|
use Adminetic\Announcement\Contracts\AnnouncementRepositoryInterface; |
6
|
|
|
use Adminetic\Announcement\Models\Admin\Announcement; |
7
|
|
|
use Adminetic\Announcement\Policies\AnnouncementPolicy; |
8
|
|
|
use Adminetic\Announcement\Repositories\AnnouncementRepository; |
9
|
|
|
use Adminetic\Announcement\View\Components\AnnouncementNotificationBell; |
10
|
|
|
use Illuminate\Support\Facades\Gate; |
11
|
|
|
use Illuminate\Support\Facades\Route; |
12
|
|
|
use Illuminate\Support\ServiceProvider; |
13
|
|
|
|
14
|
|
|
class AnnouncementServiceProvider extends ServiceProvider |
15
|
|
|
{ |
16
|
|
|
// Register Policies |
17
|
|
|
protected $policies = [ |
18
|
|
|
Announcement::class => AnnouncementPolicy::class, |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Bootstrap services. |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function boot() |
27
|
|
|
{ |
28
|
|
|
// Publish Ressource |
29
|
|
|
if ($this->app->runningInConsole()) { |
30
|
|
|
$this->publishResource(); |
31
|
|
|
} |
32
|
|
|
// Register Resources |
33
|
|
|
$this->registerResource(); |
34
|
|
|
// Register Policies |
35
|
|
|
$this->registerPolicies(); |
36
|
|
|
// Register View Components |
37
|
|
|
$this->registerComponents(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register services. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function register() |
46
|
|
|
{ |
47
|
|
|
/* Repository Interface Binding */ |
48
|
|
|
$this->repos(); |
49
|
|
|
/* Register AnnouncementEventServiceProvider */ |
50
|
|
|
$this->app->register(AnnouncementEventServiceProvider::class); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Publish Package Resource. |
55
|
|
|
* |
56
|
|
|
*@return void |
57
|
|
|
*/ |
58
|
|
|
protected function publishResource() |
59
|
|
|
{ |
60
|
|
|
// Publish Config File |
61
|
|
|
$this->publishes([ |
62
|
|
|
__DIR__.'/../../config/announcement.php' => config_path('announcement.php'), |
63
|
|
|
], 'announcement-config'); |
64
|
|
|
// Publish View Files |
65
|
|
|
$this->publishes([ |
66
|
|
|
__DIR__.'/../../resources/views' => resource_path('views/vendor/adminetic/plugin/announcement'), |
67
|
|
|
], 'announcement-views'); |
68
|
|
|
// Publish Migration Files |
69
|
|
|
$this->publishes([ |
70
|
|
|
__DIR__.'/../../database/migrations' => database_path('migrations'), |
71
|
|
|
], 'announcement-migrations'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Register Package Resource. |
76
|
|
|
* |
77
|
|
|
*@return void |
78
|
|
|
*/ |
79
|
|
|
protected function registerResource() |
80
|
|
|
{ |
81
|
|
|
$this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); // Loading Migration Files |
82
|
|
|
$this->loadViewsFrom(__DIR__.'/../../resources/views', 'announcement'); // Loading Views Files |
83
|
|
|
$this->registerRoutes(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Register Routes. |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
protected function registerRoutes() |
92
|
|
|
{ |
93
|
|
|
Route::group($this->routeConfiguration(), function () { |
|
|
|
|
94
|
|
|
$this->loadRoutesFrom(__DIR__.'/../../routes/web.php'); |
95
|
|
|
}); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Register Route Configuration. |
100
|
|
|
* |
101
|
|
|
* @return void |
102
|
|
|
*/ |
103
|
|
|
protected function routeConfiguration() |
104
|
|
|
{ |
105
|
|
|
return [ |
|
|
|
|
106
|
|
|
'prefix' => config('announcement.prefix', 'admin'), |
107
|
|
|
'middleware' => config('announcement.middleware', ['web', 'auth']), |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Register Components. |
113
|
|
|
* |
114
|
|
|
*@return void |
115
|
|
|
*/ |
116
|
|
|
protected function registerComponents() |
117
|
|
|
{ |
118
|
|
|
$this->loadViewComponentsAs('announcement', [ |
119
|
|
|
AnnouncementNotificationBell::class, |
120
|
|
|
]); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Repository Binding. |
125
|
|
|
* |
126
|
|
|
* @return void |
127
|
|
|
*/ |
128
|
|
|
protected function repos() |
129
|
|
|
{ |
130
|
|
|
$this->app->bind(AnnouncementRepositoryInterface::class, AnnouncementRepository::class); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* Register Policies. |
135
|
|
|
* |
136
|
|
|
*@return void |
137
|
|
|
*/ |
138
|
|
|
protected function registerPolicies() |
139
|
|
|
{ |
140
|
|
|
foreach ($this->policies as $key => $value) { |
141
|
|
|
Gate::policy($key, $value); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|