1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace RexlManu\LaravelTickets; |
4
|
|
|
|
5
|
|
|
use Illuminate\Routing\Router; |
6
|
|
|
use Illuminate\Support\Facades\Route; |
7
|
|
|
use Illuminate\Support\ServiceProvider; |
8
|
|
|
use RexlManu\LaravelTickets\Commands\AutoCloseCommand; |
9
|
|
|
use RexlManu\LaravelTickets\Models\Ticket; |
10
|
|
|
use RexlManu\LaravelTickets\Models\TicketMessage; |
11
|
|
|
use RexlManu\LaravelTickets\Models\TicketUpload; |
12
|
|
|
use RexlManu\LaravelTickets\Observers\TicketMessageObserver; |
13
|
|
|
use RexlManu\LaravelTickets\Observers\TicketObserver; |
14
|
|
|
use RexlManu\LaravelTickets\Observers\TicketUploadObserver; |
15
|
|
|
|
16
|
|
|
class LaravelTicketsServiceProvider extends ServiceProvider |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Bootstrap the application services. |
20
|
|
|
*/ |
21
|
|
|
public function boot() |
22
|
|
|
{ |
23
|
|
|
/* |
24
|
|
|
* Optional methods to load your package assets |
25
|
|
|
*/ |
26
|
|
|
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'laravel-tickets'); |
27
|
|
|
$this->loadViewsFrom(__DIR__ . '/../resources/views', 'laravel-tickets'); |
28
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
29
|
|
|
$this->routes(); |
30
|
|
|
$this->observers(); |
31
|
|
|
|
32
|
|
|
if ($this->app->runningInConsole()) { |
33
|
|
|
$this->publishes([ |
34
|
|
|
__DIR__ . '/../config/config.php' => config_path('laravel-tickets.php'), |
35
|
|
|
], 'config'); |
36
|
|
|
|
37
|
|
|
// Publishing the views. |
38
|
|
|
$this->publishes([ |
39
|
|
|
__DIR__ . '/../resources/views' => resource_path('views/vendor/laravel-tickets'), |
40
|
|
|
], 'views'); |
41
|
|
|
|
42
|
|
|
$this->publishes([ |
43
|
|
|
__DIR__ . '/../database/migrations' => database_path('migrations'), |
44
|
|
|
], 'migrations'); |
45
|
|
|
|
46
|
|
|
// Publishing assets. |
47
|
|
|
/*$this->publishes([ |
48
|
|
|
__DIR__.'/../resources/assets' => public_path('vendor/laravel-tickets'), |
49
|
|
|
], 'assets');*/ |
50
|
|
|
|
51
|
|
|
// Publishing the translation files. |
52
|
|
|
$this->publishes([ |
53
|
|
|
__DIR__ . '/../resources/lang' => resource_path('lang/vendor/laravel-tickets'), |
54
|
|
|
], 'lang'); |
55
|
|
|
|
56
|
|
|
if (config('laravel-tickets.autoclose-days') > 0) { |
57
|
|
|
// Registering package commands. |
58
|
|
|
$this->commands([ AutoCloseCommand::class ]); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Register the application services. |
65
|
|
|
*/ |
66
|
|
|
public function register() |
67
|
|
|
{ |
68
|
|
|
// Automatically apply the package configuration |
69
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'laravel-tickets'); |
70
|
|
|
|
71
|
|
|
// Register the main class to use with the facade |
72
|
|
|
$this->app->singleton('laravel-tickets', function () { |
73
|
|
|
return new LaravelTickets; |
74
|
|
|
}); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function routes() |
78
|
|
|
{ |
79
|
|
|
// Macro routing |
80
|
|
|
foreach ([ 'ticketSystem', 'tickets' ] as $routeMacroName) { |
81
|
|
|
Router::macro($routeMacroName, function ($controller) { |
82
|
|
|
Route::middleware(config('laravel-tickets.guard'))->name('laravel-tickets.')->group(function () use ($controller) { |
83
|
|
|
Route::prefix('/tickets')->group(function () use ($controller) { |
84
|
|
|
Route::get('/', [ $controller, 'index' ])->name('tickets.index'); |
85
|
|
|
Route::post('/', [ $controller, 'store' ])->name('tickets.store'); |
86
|
|
|
Route::get('/create', [ $controller, 'create' ])->name('tickets.create'); |
87
|
|
|
Route::prefix('{ticket}')->group(function () use ($controller) { |
88
|
|
|
Route::get('/', [ $controller, 'show' ])->name('tickets.show'); |
89
|
|
|
Route::post('/', [ $controller, 'close' ])->name('tickets.close'); |
90
|
|
|
Route::post('/message', [ $controller, 'message' ])->name('tickets.message'); |
91
|
|
|
Route::prefix('{ticketUpload}')->group(function () use ($controller) { |
92
|
|
|
Route::get('/download', [ $controller, 'download' ])->name('tickets.download'); |
93
|
|
|
}); |
94
|
|
|
}); |
95
|
|
|
}); |
96
|
|
|
}); |
97
|
|
|
}); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function observers() |
102
|
|
|
{ |
103
|
|
|
Ticket::observe(TicketObserver::class); |
104
|
|
|
TicketMessage::observe(TicketMessageObserver::class); |
105
|
|
|
TicketUpload::observe(TicketUploadObserver::class); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|