|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Tenants\Http\Controllers\Adminarea; |
|
6
|
|
|
|
|
7
|
|
|
use Rinvex\Tenants\Models\Tenant; |
|
8
|
|
|
use Illuminate\Foundation\Http\FormRequest; |
|
9
|
|
|
use Cortex\Foundation\DataTables\LogsDataTable; |
|
10
|
|
|
use Cortex\Tenants\DataTables\Adminarea\TenantsDataTable; |
|
11
|
|
|
use Cortex\Foundation\Http\Controllers\AuthorizedController; |
|
12
|
|
|
use Cortex\Tenants\Http\Requests\Adminarea\TenantFormRequest; |
|
13
|
|
|
|
|
14
|
|
|
class TenantsController extends AuthorizedController |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritdoc} |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $resource = 'tenant'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* List all tenants. |
|
23
|
|
|
* |
|
24
|
|
|
* @param \Cortex\Tenants\DataTables\Adminarea\TenantsDataTable $tenantsDataTable |
|
25
|
|
|
* |
|
26
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\View\View |
|
27
|
|
|
*/ |
|
28
|
|
|
public function index(TenantsDataTable $tenantsDataTable) |
|
29
|
|
|
{ |
|
30
|
|
|
return $tenantsDataTable->with([ |
|
31
|
|
|
'id' => 'adminarea-tenants-index-table', |
|
32
|
|
|
'phrase' => trans('cortex/tenants::common.tenants'), |
|
33
|
|
|
])->render('cortex/foundation::adminarea.pages.datatable'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* List tenant logs. |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Cortex\Tenants\Models\Tenant $tenant |
|
|
|
|
|
|
40
|
|
|
* @param \Cortex\Foundation\DataTables\LogsDataTable $logsDataTable |
|
41
|
|
|
* |
|
42
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
|
|
|
|
|
43
|
|
|
*/ |
|
44
|
|
|
public function logs(Tenant $tenant, LogsDataTable $logsDataTable) |
|
45
|
|
|
{ |
|
46
|
|
|
return $logsDataTable->with([ |
|
47
|
|
|
'resource' => $tenant, |
|
48
|
|
|
'tabs' => 'adminarea.tenants.tabs', |
|
49
|
|
|
'phrase' => trans('cortex/tenants::common.tenants'), |
|
50
|
|
|
'id' => "adminarea-tenants-{$tenant->getKey()}-logs-table", |
|
51
|
|
|
])->render('cortex/foundation::adminarea.pages.datatable-logs'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Create new tenant. |
|
56
|
|
|
* |
|
57
|
|
|
* @param \Cortex\Fort\Models\Role $tenant |
|
|
|
|
|
|
58
|
|
|
* |
|
59
|
|
|
* @return \Illuminate\View\View |
|
60
|
|
|
*/ |
|
61
|
|
|
public function create(Tenant $tenant) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->form($tenant); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Edit given tenant. |
|
68
|
|
|
* |
|
69
|
|
|
* @param \Cortex\Fort\Models\Role $tenant |
|
|
|
|
|
|
70
|
|
|
* |
|
71
|
|
|
* @return \Illuminate\View\View |
|
72
|
|
|
*/ |
|
73
|
|
|
public function edit(Tenant $tenant) |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->form($tenant); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Show tenant create/edit form. |
|
80
|
|
|
* |
|
81
|
|
|
* @param \Cortex\Tenants\Models\Tenant $tenant |
|
|
|
|
|
|
82
|
|
|
* |
|
83
|
|
|
* @return \Illuminate\View\View |
|
84
|
|
|
*/ |
|
85
|
|
|
protected function form(Tenant $tenant) |
|
86
|
|
|
{ |
|
87
|
|
|
$countries = collect(countries())->map(function ($country, $code) { |
|
88
|
|
|
return [ |
|
89
|
|
|
'id' => $code, |
|
90
|
|
|
'text' => $country['name'], |
|
91
|
|
|
'emoji' => $country['emoji'], |
|
92
|
|
|
]; |
|
93
|
|
|
})->values(); |
|
94
|
|
|
$languages = collect(languages())->pluck('name', 'iso_639_1'); |
|
95
|
|
|
$owners = app('cortex.fort.user')->withAnyRoles(['manager'])->get()->pluck('username', 'id'); |
|
96
|
|
|
$groups = app('rinvex.tenants.tenant')->distinct()->get(['group'])->pluck('group', 'group')->toArray(); |
|
97
|
|
|
|
|
98
|
|
|
return view('cortex/tenants::adminarea.pages.tenant', compact('tenant', 'owners', 'countries', 'languages', 'groups')); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Store new tenant. |
|
103
|
|
|
* |
|
104
|
|
|
* @param \Cortex\Tenants\Http\Requests\Adminarea\TenantFormRequest $request |
|
105
|
|
|
* @param \Cortex\Tenants\Models\Tenant $tenant |
|
|
|
|
|
|
106
|
|
|
* |
|
107
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
108
|
|
|
*/ |
|
109
|
|
|
public function store(TenantFormRequest $request, Tenant $tenant) |
|
110
|
|
|
{ |
|
111
|
|
|
return $this->process($request, $tenant); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Update given tenant. |
|
116
|
|
|
* |
|
117
|
|
|
* @param \Cortex\Tenants\Http\Requests\Adminarea\TenantFormRequest $request |
|
118
|
|
|
* @param \Cortex\Tenants\Models\Tenant $tenant |
|
|
|
|
|
|
119
|
|
|
* |
|
120
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
121
|
|
|
*/ |
|
122
|
|
|
public function update(TenantFormRequest $request, Tenant $tenant) |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->process($request, $tenant); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Process stored/updated tenant. |
|
129
|
|
|
* |
|
130
|
|
|
* @param \Illuminate\Foundation\Http\FormRequest $request |
|
131
|
|
|
* @param \Cortex\Tenants\Models\Tenant $tenant |
|
|
|
|
|
|
132
|
|
|
* |
|
133
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
134
|
|
|
*/ |
|
135
|
|
|
protected function process(FormRequest $request, Tenant $tenant) |
|
136
|
|
|
{ |
|
137
|
|
|
// Prepare required input fields |
|
138
|
|
|
$data = $request->validated(); |
|
139
|
|
|
|
|
140
|
|
|
// Save tenant |
|
141
|
|
|
$tenant->fill($data)->save(); |
|
142
|
|
|
|
|
143
|
|
|
return intend([ |
|
144
|
|
|
'url' => route('adminarea.tenants.index'), |
|
145
|
|
|
'with' => ['success' => trans('cortex/foundation::messages.resource_saved', ['resource' => 'tenant', 'id' => $tenant->slug])], |
|
|
|
|
|
|
146
|
|
|
]); |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Destroy given tenant. |
|
151
|
|
|
* |
|
152
|
|
|
* @param \Cortex\Tenants\Models\Tenant $tenant |
|
|
|
|
|
|
153
|
|
|
* |
|
154
|
|
|
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse |
|
155
|
|
|
*/ |
|
156
|
|
|
public function destroy(Tenant $tenant) |
|
157
|
|
|
{ |
|
158
|
|
|
$tenant->delete(); |
|
159
|
|
|
|
|
160
|
|
|
return intend([ |
|
161
|
|
|
'url' => route('adminarea.tenants.index'), |
|
162
|
|
|
'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => 'tenant', 'id' => $tenant->slug])], |
|
|
|
|
|
|
163
|
|
|
]); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|