File tree Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -69,4 +69,13 @@ public function getBySlug($slug)
6969 {
7070 return $ this ->model ->with ('author ' )->where ('slug ' , '= ' , $ slug )->first ();
7171 }
72+
73+ /**
74+ * @param int $userId
75+ * @return mixed
76+ */
77+ public function deleteByAuthorId ($ userId )
78+ {
79+ return $ this ->model ->where ('author_id ' , $ userId )->delete ();
80+ }
7281}
Original file line number Diff line number Diff line change 11<?php namespace Admin ;
22
33use BaseController ;
4+ use Input ;
45use Lio \Accounts \UserRepository ;
56use Lio \Accounts \RoleRepository ;
6- use Input ;
7+ use Lio \ Forum \ Threads \ ThreadRepository ;
78
89class UsersController extends BaseController
910{
1011 private $ users ;
1112 private $ roles ;
1213
13- public function __construct (UserRepository $ users , RoleRepository $ roles )
14+ /**
15+ * @var \Lio\Forum\Threads\ThreadRepository
16+ */
17+ private $ threads ;
18+
19+ public function __construct (UserRepository $ users , RoleRepository $ roles , ThreadRepository $ threads )
1420 {
1521 $ this ->users = $ users ;
1622 $ this ->roles = $ roles ;
23+ $ this ->threads = $ threads ;
1724 }
1825
1926 public function getIndex ()
@@ -49,4 +56,18 @@ public function postEdit($userId)
4956
5057 return $ this ->redirectAction ('Admin\UsersController@getIndex ' , ['success ' => 'The user has been saved. ' ]);
5158 }
59+
60+ public function putBanAndDeleteThreads ($ userId )
61+ {
62+ // Ban the user
63+ $ user = $ this ->users ->requireById ($ userId );
64+ $ user ->is_banned = 1 ;
65+
66+ $ this ->users ->save ($ user );
67+
68+ // Remove all threads by the user
69+ $ this ->threads ->deleteByAuthorId ($ userId );
70+
71+ return $ this ->redirectAction ('Admin\UsersController@getIndex ' , ['success ' => 'The user has been banned and its threads have been removed. ' ]);
72+ }
5273}
Original file line number Diff line number Diff line change 110110 Route::get ('users ' , 'UsersController@getIndex ' );
111111 Route::get ('edit/{user} ' , 'UsersController@getEdit ' );
112112 Route::post ('edit/{user} ' , 'UsersController@postEdit ' );
113+ Route::put ('ban-and-delete-threads/{user} ' , 'UsersController@putBanAndDeleteThreads ' );
113114 });
114115});
Original file line number Diff line number Diff line change 5050 {{ Form:: button (' Save' , [' type' => ' submit' ]) } }
5151 </div >
5252 </div >
53-
5453 {{ Form:: close () } }
54+
55+ @if (! $user -> is_banned )
56+ {{ Form:: open ([' action' => [' Admin\UsersController@putBanAndDeleteThreads' , $user -> id ], ' method' => ' put' ]) } }
57+ <div class =" row" >
58+ <div class =" large-12 columns" >
59+ {{ Form:: button (' Ban and delete threads' , [' type' => ' submit' ]) } }
60+ </div >
61+ </div >
62+ {{ Form:: close () } }
63+ @endif
5564 </div >
5665</div >
You can’t perform that action at this time.
0 commit comments