1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Dashboard; |
4
|
|
|
|
5
|
|
|
use App\Person; |
6
|
|
|
use Illuminate\Routing\Controller; |
7
|
|
|
use LaravelEnso\Charts\Factories\Bar; |
8
|
|
|
use LaravelEnso\Charts\Factories\Bubble; |
9
|
|
|
use LaravelEnso\Charts\Factories\Doughnut; |
10
|
|
|
use LaravelEnso\Charts\Factories\Line; |
11
|
|
|
use LaravelEnso\Charts\Factories\Pie; |
12
|
|
|
use LaravelEnso\Charts\Factories\Polar; |
13
|
|
|
use LaravelEnso\Charts\Factories\Radar; |
14
|
|
|
use Illuminate\Support\Facades\Auth; |
15
|
|
|
use LaravelEnso\Multitenancy\Enums\Connections; |
16
|
|
|
use LaravelEnso\Multitenancy\Services\Tenant; |
17
|
|
|
// use LaravelEnso\Multitenancy\Traits\SystemConnection; |
18
|
|
|
|
19
|
|
|
class ChartController extends Controller |
20
|
|
|
{ |
21
|
|
|
// use SystemConnection; |
22
|
|
|
|
23
|
|
|
public function line() |
24
|
|
|
{ |
25
|
|
|
return (new Line()) |
26
|
|
|
->title('Income') |
27
|
|
|
->labels(['January', 'February', 'March', 'April', 'May', 'June', 'July']) |
28
|
|
|
->datasets([ |
29
|
|
|
'Sales' => [65, 59, 80, 81, 26, 25, 10], |
30
|
|
|
'Revenue' => [15, 29, 60, 31, 56, 65, 44], |
31
|
|
|
])->fill() |
32
|
|
|
->get(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function bar() |
36
|
|
|
{ |
37
|
|
|
return (new Bar()) |
38
|
|
|
->title('Sales') |
39
|
|
|
->labels(['Ian', 'Feb', 'Mar']) |
40
|
|
|
->datasets([ |
41
|
|
|
'Sales' => [1233, 1231, 3123], |
42
|
|
|
'Spendings' => [1250, 1730, 5300], |
43
|
|
|
'Profit' => [1250 - 1233, 1730 - 1231, 5300 - 3123], |
44
|
|
|
])->get(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function pie() |
48
|
|
|
{ |
49
|
|
|
// \DB::table('some')->get(); |
50
|
|
|
|
51
|
|
|
$male = Person::where('sex', 'M')->get()->count(); |
52
|
|
|
$female = Person::where('sex', 'F')->get()->count(); |
53
|
|
|
$unknown = Person::whereNull('sex')->get()->count(); |
54
|
|
|
$sv = \Session::get('db', env('DB_DATABASE')); |
|
|
|
|
55
|
|
|
$user = Auth::user(); |
|
|
|
|
56
|
|
|
$sv = \DB::connection()->getDatabaseName(); |
57
|
|
|
|
58
|
|
|
// return $user; |
59
|
|
|
return (new Pie()) |
60
|
|
|
->title('Genders') |
61
|
|
|
->labels(['Male', 'Female', 'Unknown']) |
62
|
|
|
->datasets([$male, $female, $unknown]) |
63
|
|
|
->get(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function doughnut() |
67
|
|
|
{ |
68
|
|
|
return (new Doughnut()) |
69
|
|
|
->title('Colors Two') |
70
|
|
|
->labels(['Green', 'Red', 'Azzure']) |
71
|
|
|
->datasets([400, 50, 100]) |
72
|
|
|
->get(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function radar() |
76
|
|
|
{ |
77
|
|
|
return (new Radar()) |
78
|
|
|
->title('Habits') |
79
|
|
|
->labels([ |
80
|
|
|
'Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running', |
81
|
|
|
]) |
82
|
|
|
->datasets([ |
83
|
|
|
'2005' => [65, 59, 90, 81, 56, 55, 40], |
84
|
|
|
'2006' => [28, 48, 40, 19, 96, 27, 100], |
85
|
|
|
])->get(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function polar() |
89
|
|
|
{ |
90
|
|
|
return (new Polar()) |
91
|
|
|
->title('Again Colors') |
92
|
|
|
->labels(['Green', 'Red', 'Azzure', 'Portocaliu', 'Purple']) |
93
|
|
|
->datasets([11, 16, 7, 14, 14]) |
94
|
|
|
->get(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function bubble() |
98
|
|
|
{ |
99
|
|
|
return (new Bubble()) |
100
|
|
|
->title('City Population by Age') |
101
|
|
|
->labels(['Geneva', 'Besel', 'Bucharest']) |
102
|
|
|
->datasets([ |
103
|
|
|
0 => [[1010, 59, 4800], [2011, 55, 1800], [1012, 45, 2000], [413, 58, 4400]], |
104
|
|
|
1 => [[2010, 48, 1700], [1211, 67, 1200], [2012, 96, 1233], [813, 35, 3000]], |
105
|
|
|
2 => [[1510, 44, 2000], [811, 62, 1500], [212, 55, 1299], [1213, 39, 4000]], |
106
|
|
|
])->get(); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function changedb() { |
110
|
|
|
$user = Auth::user(); |
111
|
|
|
$user->role_id = 1; |
|
|
|
|
112
|
|
|
$user->save(); |
113
|
|
|
$company = $user->company(); |
|
|
|
|
114
|
|
|
$tenant = false; |
|
|
|
|
115
|
|
|
if ($company) { |
116
|
|
|
$tenant = true; |
117
|
|
|
} |
118
|
|
|
$value = env('DB_DATABASE'); |
119
|
|
|
if (optional($company)->isTenant()) { |
120
|
|
|
// $key = 'database.default'; |
121
|
|
|
// $value = Connections::Tenant; |
122
|
|
|
// config([$key => $value]); |
123
|
|
|
// Tenant::set($company); |
124
|
|
|
$value = Connections::Tenant.$company->id; |
125
|
|
|
} else { |
126
|
|
|
// $value = ''; |
127
|
|
|
} |
128
|
|
|
$key = 'database.connections.mysql.database'; |
129
|
|
|
config([$key => $value]); |
130
|
|
|
|
131
|
|
|
\DB::purge('mysql'); |
132
|
|
|
|
133
|
|
|
\DB::setDefaultConnection('mysql'); |
134
|
|
|
$users = \DB::table('users')->get(); |
|
|
|
|
135
|
|
|
\Session::put('db', $value); |
136
|
|
|
$sv = \Session::get('db', env('DB_DATABASE')); |
137
|
|
|
|
138
|
|
|
return $sv; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|