10
10
use Flash ;
11
11
use App \Http \Controllers \AppBaseController ;
12
12
use Response ;
13
- use Illuminate \Support \Facades \Auth ; // add by dandisy
14
- use Illuminate \Support \Facades \Storage ; // add by dandisy
13
+ use Illuminate \Support \Facades \Auth ; // added by dandisy
14
+ use Illuminate \Support \Facades \Storage ; // added by dandisy
15
+ use Illuminate \Http \Request ;
16
+ use App \User ;
15
17
16
18
class ProfileController extends AppBaseController
17
19
{
@@ -42,11 +44,13 @@ public function index(ProfileDataTable $profileDataTable)
42
44
*/
43
45
public function create ()
44
46
{
45
- // add by dandisy
46
-
47
+ if (Auth::user ()->hasRole (['superadministrator ' ])) {
48
+ $ user = User::all ();
49
+
50
+ return view ('profiles.create ' )
51
+ ->with ('user ' , $ user );
52
+ }
47
53
48
- // edit by dandisy
49
- //return view('profiles.create');
50
54
return view ('profiles.create ' );
51
55
}
52
56
@@ -61,12 +65,22 @@ public function store(CreateProfileRequest $request)
61
65
{
62
66
$ input = $ request ->all ();
63
67
68
+ // handling edit profile non superadmin
69
+ if (Auth::user ()->hasRole (['administrator ' ,'user ' ])) {
70
+ $ input ['user_id ' ] = Auth::user ()->id ;
71
+ }
72
+
64
73
$ input ['created_by ' ] = Auth::user ()->id ;
65
74
66
75
$ profile = $ this ->profileRepository ->create ($ input );
67
76
68
77
Flash::success ('Profile saved successfully. ' );
69
78
79
+ // handling edit profile non superadmin
80
+ if (Auth::user ()->hasRole (['administrator ' ,'user ' ])) {
81
+ return redirect (url ('dashboard ' ));
82
+ }
83
+
70
84
return redirect (route ('profiles.index ' ));
71
85
}
72
86
@@ -99,19 +113,33 @@ public function show($id)
99
113
*/
100
114
public function edit ($ id )
101
115
{
102
- // add by dandisy
103
-
104
-
105
- $ profile = $ this ->profileRepository ->findWithoutFail ($ id );
116
+ $ profile = NULL ;
117
+ if (Auth::user ()->hasRole (['administrator ' ,'user ' ])) {
118
+ $ profile = $ this ->profileRepository ->findWhere (['user_id ' => Auth::user ()->id ])->first ();
119
+ }
120
+ if (Auth::user ()->hasRole (['superadministrator ' ])) {
121
+ $ profile = $ this ->profileRepository ->findWithoutFail ($ id );
122
+ }
106
123
107
124
if (empty ($ profile )) {
125
+ // handling edit profile non superadmin
126
+ if (Auth::user ()->hasRole (['superadministrator ' ,'administrator ' ,'user ' ])) {
127
+ return redirect (url ('profiles/create ' ));
128
+ }
129
+
108
130
Flash::error ('Profile not found ' );
109
131
110
132
return redirect (route ('profiles.index ' ));
111
133
}
134
+
135
+ if (Auth::user ()->hasRole (['superadministrator ' ])) {
136
+ $ user = User::all ();
112
137
113
- // edit by dandisy
114
- //return view('profiles.edit')->with('profile', $profile);
138
+ return view ('profiles.edit ' )
139
+ ->with ('user ' , $ user )
140
+ ->with ('profile ' , $ profile );
141
+ }
142
+
115
143
return view ('profiles.edit ' )
116
144
->with ('profile ' , $ profile );
117
145
}
@@ -130,18 +158,34 @@ public function update($id, UpdateProfileRequest $request)
130
158
131
159
$ input ['updated_by ' ] = Auth::user ()->id ;
132
160
133
- $ profile = $ this ->profileRepository ->findWithoutFail ($ id );
161
+ $ profile = NULL ;
162
+ if (Auth::user ()->hasRole (['administrator ' ,'user ' ])) {
163
+ $ profile = $ this ->profileRepository ->findWhere (['user_id ' => Auth::user ()->id ])->first ();
164
+ }
165
+ if (Auth::user ()->hasRole (['superadministrator ' ])) {
166
+ $ profile = $ this ->profileRepository ->findWithoutFail ($ id );
167
+ }
134
168
135
169
if (empty ($ profile )) {
136
170
Flash::error ('Profile not found ' );
171
+
172
+ // handling edit profile non superadmin
173
+ if (Auth::user ()->hasRole (['administrator ' ,'user ' ])) {
174
+ return redirect (url ('dashboard ' ));
175
+ }
137
176
138
177
return redirect (route ('profiles.index ' ));
139
178
}
140
179
141
- $ profile = $ this ->profileRepository ->update ($ input , $ id );
180
+ $ profile = $ this ->profileRepository ->update ($ input , $ profile -> id );
142
181
143
182
Flash::success ('Profile updated successfully. ' );
144
183
184
+ // handling edit profile non superadmin
185
+ if (Auth::user ()->hasRole (['administrator ' ,'user ' ])) {
186
+ return redirect (url ('dashboard ' ));
187
+ }
188
+
145
189
return redirect (route ('profiles.index ' ));
146
190
}
147
191
0 commit comments