|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Repositories\UserRepository; |
|
6
|
|
|
use App\Repositories\LotRepository; |
|
7
|
|
|
use App\Repositories\ProfileRepository; |
|
8
|
|
|
use App\Repositories\InvolvedRepository; |
|
9
|
|
|
use Carbon\Carbon; |
|
10
|
|
|
use Illuminate\Contracts\Auth\Guard; |
|
11
|
|
|
use App\Http\Requests\UpdateUserSettings; |
|
12
|
|
|
use App\Http\Requests\UpdateUserPassword; |
|
13
|
|
|
use App\Services\ImageProcessor; |
|
14
|
|
|
use App\Video; |
|
15
|
|
|
use Illuminate\Http\UploadedFile; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
class DashboardController extends Controller |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var UserRepository |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $users; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var ProfileRepository |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $profile; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var Guard |
|
32
|
|
|
*/ |
|
33
|
|
|
private $auth; |
|
34
|
|
|
|
|
35
|
|
|
private $lots; |
|
36
|
|
|
|
|
37
|
|
|
private $involved; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* DashboardController constructor. |
|
41
|
|
|
* @param UserRepository $userRepository |
|
42
|
|
|
* @param Guard $auth |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct(UserRepository $userRepository, |
|
45
|
|
|
Guard $auth, |
|
46
|
|
|
ProfileRepository $profileRepository, |
|
47
|
|
|
LotRepository $lotRepository, |
|
48
|
|
|
InvolvedRepository $involvedRepository |
|
49
|
|
|
) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->users = $userRepository; |
|
52
|
|
|
$this->profile = $profileRepository; |
|
53
|
|
|
$this->auth = $auth; |
|
54
|
|
|
$this->lots = $lotRepository; |
|
55
|
|
|
$this->involved = $involvedRepository; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function howWork() |
|
59
|
|
|
{ |
|
60
|
|
|
|
|
61
|
|
|
$video = Video::orderBy('id', 'desc')->get(); |
|
62
|
|
|
|
|
63
|
|
|
return view('dashboard.how-amma-work', compact('video')); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* My vendors. |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
70
|
|
|
*/ |
|
71
|
|
|
public function myVendors() |
|
72
|
|
|
{ |
|
73
|
|
|
$vendors = $this->auth->user()->vendors; |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
return view('dashboard.my-vendors', compact('vendors')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* My products. |
|
80
|
|
|
* |
|
81
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
82
|
|
|
*/ |
|
83
|
|
|
public function myProducts() |
|
84
|
|
|
{ |
|
85
|
|
|
$vendors = $this->auth->user()->vendors; |
|
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
return view('dashboard.my-products', compact('vendors')); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* My products. |
|
92
|
|
|
* |
|
93
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
94
|
|
|
*/ |
|
95
|
|
|
public function myInvolved() |
|
96
|
|
|
{ |
|
97
|
|
|
$involved = $this->auth->user()->involved()->active()->get(); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$product = $this->sortInvolvedProducts($involved); |
|
100
|
|
|
|
|
101
|
|
|
return view('dashboard.my-involved', compact('product')); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function sortInvolvedProducts($involved) { |
|
105
|
|
|
|
|
106
|
|
|
if (count($involved)) { |
|
107
|
|
|
foreach ($involved as $item) { |
|
108
|
|
|
if ($item->lot->verify_status == 'verified') { |
|
109
|
|
|
$product[] = ['date' =>$item->lot->public_date, 'product' => $item->product, 'involved' => $item]; |
|
|
|
|
|
|
110
|
|
|
}else { |
|
111
|
|
|
$product[] = ['date' =>date('dmy',strtotime('9999999')), 'product' => $item->product, 'involved' => $item]; |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
usort($product, function ($product, $b) { |
|
115
|
|
|
return date('dmy',strtotime($b['date'])) - date('dmy',strtotime($product['date'])); |
|
116
|
|
|
}); |
|
117
|
|
|
|
|
118
|
|
|
return $product; |
|
119
|
|
|
} |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* Account and password settings. |
|
124
|
|
|
* |
|
125
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|
126
|
|
|
*/ |
|
127
|
|
|
public function accountSettings() |
|
128
|
|
|
{ |
|
129
|
|
|
return view('dashboard.account-settings'); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function userPassword() |
|
133
|
|
|
{ |
|
134
|
|
|
return view('dashboard.user-password'); |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param UpdateUserSettings $request |
|
139
|
|
|
* @return mixed |
|
140
|
|
|
*/ |
|
141
|
|
|
public function update(UpdateUserSettings $request) |
|
142
|
|
|
{ |
|
143
|
|
|
$this->users->update_user($request->all()); |
|
144
|
|
|
|
|
145
|
|
|
$image = $request->file('photo'); |
|
146
|
|
|
if ($image && $image instanceof UploadedFile) { |
|
147
|
|
|
(new ImageProcessor())->changeAvatar($image); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
return back()->withStatus('Setarile au fost modificate!')->withColor('green')->with('activeclass', 'update_settings'); |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param UpdateUserPassword $request |
|
155
|
|
|
* @return mixed |
|
156
|
|
|
*/ |
|
157
|
|
|
public function updatePassword(UpdateUserPassword $request) |
|
158
|
|
|
{ |
|
159
|
|
|
$this->users->updatePassword($request->password); |
|
|
|
|
|
|
160
|
|
|
|
|
161
|
|
|
return back()->withStatus('Password Updated!')->with('activeclass', 'update_password'); |
|
|
|
|
|
|
162
|
|
|
} |
|
163
|
|
|
} |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: