1919class UserController extends Controller
2020{
2121
22+ protected $ model = \Smarch \Watchtower \Models \User::class;
23+
2224 /**
23- * Set resource in constructor.
25+ * Set resource model in constructor.
2426 */
25- function __construct () {}
27+ function __construct () {
28+ $ this ->model = $ this ->getModel ();
29+ }
30+
31+
32+ /**
33+ * Determine which model to use
34+ * @return Model Instance
35+ */
36+ function getModel () {
37+ $ model = config ('watchtower.user.model ' , $ this ->model );
38+ return new $ model ;
39+ }
40+
2641
2742 /**
2843 * Display a listing of the resource.
@@ -34,11 +49,11 @@ public function index(Request $request)
3449 if ( Shinobi::can ( config ('watchtower.acl.user.index ' , false ) ) ) {
3550 if ( $ request ->has ('search_value ' ) ) {
3651 $ value = $ request ->get ('search_value ' );
37- $ users = User ::where ('name ' , 'LIKE ' , '% ' .$ value .'% ' )
52+ $ users = $ this -> model ::where ('name ' , 'LIKE ' , '% ' .$ value .'% ' )
3853 ->orderBy ('name ' )->paginate ( config ('watchtower.pagination.users ' , 15 ) );
3954 session ()->flash ('search_value ' , $ value );
4055 } else {
41- $ users = User ::orderBy ('name ' )->paginate ( config ('watchtower.pagination.users ' , 15 ) );
56+ $ users = $ this -> model ::orderBy ('name ' )->paginate ( config ('watchtower.pagination.users ' , 15 ) );
4257 session ()->forget ('search_value ' );
4358 }
4459
@@ -48,6 +63,7 @@ public function index(Request $request)
4863 return view ( config ('watchtower.views.layouts.unauthorized ' ), [ 'message ' => 'view user list ' ]);
4964 }
5065
66+
5167 /**
5268 * Show the form for creating a new resource.
5369 *
@@ -74,7 +90,7 @@ public function store(UserStoreRequest $request)
7490 $ message = " You are not permitted to create users. " ;
7591
7692 if ( Shinobi::can ( config ('watchtower.acl.user.create ' , false ) ) ) {
77- User ::create ($ request ->all ());
93+ $ this -> model ::create ($ request ->all ());
7894 $ level = "success " ;
7995 $ message = "<i class='fa fa-check-square-o fa-1x'></i> Success! User created. " ;
8096 }
@@ -92,7 +108,7 @@ public function store(UserStoreRequest $request)
92108 public function show ($ id )
93109 {
94110 if ( Shinobi::canAtLeast ( [ config ('watchtower.acl.user.show ' , false ), config ('watchtower.acl.user.edit ' , false ) ] ) ) {
95- $ resource = User ::findOrFail ($ id );
111+ $ resource = $ this -> model ::findOrFail ($ id );
96112 $ show = "1 " ;
97113 return view ( config ('watchtower.views.users.show ' ), compact ('resource ' ,'show ' ) );
98114 }
@@ -109,7 +125,7 @@ public function show($id)
109125 public function edit ($ id )
110126 {
111127 if ( Shinobi::canAtLeast ( [ config ('watchtower.acl.user.edit ' , false ), config ('watchtower.acl.user.show ' , false ) ] ) ) {
112- $ resource = User ::findOrFail ($ id );
128+ $ resource = $ this -> model ::findOrFail ($ id );
113129 $ show = "0 " ;
114130 return view ( config ('watchtower.views.users.edit ' ), compact ('resource ' ,'show ' ) );
115131 }
@@ -129,7 +145,7 @@ public function update($id, UserUpdateRequest $request)
129145 $ message = " You are not permitted to update users. " ;
130146
131147 if ( Shinobi::can ( config ('watchtower.acl.user.edit ' , false ) ) ) {
132- $ user = User ::findOrFail ($ id );
148+ $ user = $ this -> model ::findOrFail ($ id );
133149 if ($ request ->get ('password ' ) == '' ) {
134150 $ user ->update ( $ request ->except ('password ' ) );
135151 } else {
@@ -155,7 +171,7 @@ public function destroy($id)
155171 $ message = " You are not permitted to destroy user objects " ;
156172
157173 if ( Shinobi::can ( config ('watchtower.acl.user.destroy ' , false ) ) ) {
158- User ::destroy ($ id );
174+ $ this -> model ::destroy ($ id );
159175 $ level = "warning " ;
160176 $ message = "<i class='fa fa-check-square-o fa-1x'></i> Success! User deleted. " ;
161177 }
@@ -173,7 +189,7 @@ public function destroy($id)
173189 public function editUserRoles ($ id )
174190 {
175191 if ( Shinobi::can ( config ('watchtower.acl.user.role ' , false ) ) ) {
176- $ user = User ::findOrFail ($ id );
192+ $ user = $ this -> model ::findOrFail ($ id );
177193
178194 $ roles = $ user ->roles ;
179195
@@ -199,7 +215,7 @@ public function updateUserRoles($id, Request $request)
199215 $ message = " You are not permitted to update user roles. " ;
200216
201217 if ( Shinobi::can ( config ('watchtower.acl.user.role ' , false ) ) ) {
202- $ user = User ::findOrFail ($ id );
218+ $ user = $ this -> model ::findOrFail ($ id );
203219 if ($ request ->has ('ids ' )) {
204220 $ user ->roles ()->sync ( $ request ->get ('ids ' ) );
205221 } else {
@@ -221,7 +237,7 @@ public function showUserMatrix()
221237 {
222238 if ( Shinobi::can ( config ('watchtower.acl.user.viewmatrix ' , false ) ) ) {
223239 $ roles = Role::all ();
224- $ users = User ::orderBy ('name ' )->get ();
240+ $ users = $ this -> model ::orderBy ('name ' )->get ();
225241 $ us = DB ::table ('role_user ' )->select ('role_id as r_id ' ,'user_id as u_id ' )->get ();
226242
227243 $ pivot = [];
0 commit comments