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)
69
69
{
70
70
return $ this ->model ->with ('author ' )->where ('slug ' , '= ' , $ slug )->first ();
71
71
}
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
+ }
72
81
}
Original file line number Diff line number Diff line change 1
1
<?php namespace Admin ;
2
2
3
3
use BaseController ;
4
+ use Input ;
4
5
use Lio \Accounts \UserRepository ;
5
6
use Lio \Accounts \RoleRepository ;
6
- use Input ;
7
+ use Lio \ Forum \ Threads \ ThreadRepository ;
7
8
8
9
class UsersController extends BaseController
9
10
{
10
11
private $ users ;
11
12
private $ roles ;
12
13
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 )
14
20
{
15
21
$ this ->users = $ users ;
16
22
$ this ->roles = $ roles ;
23
+ $ this ->threads = $ threads ;
17
24
}
18
25
19
26
public function getIndex ()
@@ -49,4 +56,18 @@ public function postEdit($userId)
49
56
50
57
return $ this ->redirectAction ('Admin\UsersController@getIndex ' , ['success ' => 'The user has been saved. ' ]);
51
58
}
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
+ }
52
73
}
Original file line number Diff line number Diff line change 110
110
Route::get ('users ' , 'UsersController@getIndex ' );
111
111
Route::get ('edit/{user} ' , 'UsersController@getEdit ' );
112
112
Route::post ('edit/{user} ' , 'UsersController@postEdit ' );
113
+ Route::put ('ban-and-delete-threads/{user} ' , 'UsersController@putBanAndDeleteThreads ' );
113
114
});
114
115
});
Original file line number Diff line number Diff line change 50
50
{{ Form:: button (' Save' , [' type' => ' submit' ]) } }
51
51
</div >
52
52
</div >
53
-
54
53
{{ 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
55
64
</div >
56
65
</div >
You can’t perform that action at this time.
0 commit comments