-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
TenantController.php
50 lines (42 loc) · 1.27 KB
/
TenantController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php namespace GeneaLabs\NovaMultiTenantManager\Http\Controllers\Api;
use GeneaLabs\NovaMultiTenantManager\Services\Tenant as TenantService;
use GeneaLabs\NovaMultiTenantManager\Tenant;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Controller;
use Illuminate\Support\Collection;
class TenantController extends Controller
{
public function index() : Collection
{
return (new Tenant)
->with("website.hostnames")
->orderBy("name")
->get();
}
public function show() : Tenant
{
$tenant = (new Tenant)->findCurrent();
$tenant->load("website.hostnames");
return $tenant;
}
public function store(Request $request) : Tenant
{
$tenancyService = (new TenantService)
->create($request->domain);
$tenant = (new Tenant)->firstOrNew([
"website_id" => $tenancyService->website->id,
])
->fill($request->all());
$tenant->save();
return $tenant;
}
public function destroy(int $id) : Response
{
$tenant = (new Tenant)->findOrFail($id);
(new TenantService)
->delete($tenant->domain);
$tenant->delete();
return response(null, 204);
}
}