jeremykenedy /
laravel-material-design
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace App\Http\Controllers; |
||||
| 4 | |||||
| 5 | use App\Models\User; |
||||
| 6 | use Illuminate\Http\Request; |
||||
| 7 | use jeremykenedy\LaravelRoles\Models\Role; |
||||
| 8 | |||||
| 9 | class SoftDeletesController extends Controller |
||||
| 10 | { |
||||
| 11 | /** |
||||
| 12 | * Create a new controller instance. |
||||
| 13 | * |
||||
| 14 | * @return void |
||||
| 15 | */ |
||||
| 16 | public function __construct() |
||||
| 17 | { |
||||
| 18 | $this->middleware('auth'); |
||||
| 19 | } |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * Get Soft Deleted User. |
||||
| 23 | * |
||||
| 24 | * @param int $id |
||||
| 25 | * |
||||
| 26 | * @return \Illuminate\Http\Response |
||||
| 27 | */ |
||||
| 28 | public static function getDeletedUser($id) |
||||
| 29 | { |
||||
| 30 | $user = User::onlyTrashed()->where('id', $id)->get(); |
||||
| 31 | if (count($user) != 1) { |
||||
| 32 | return redirect('/users/deleted/')->with('error', trans('usersmanagement.errorUserNotFound')); |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 33 | } |
||||
| 34 | |||||
| 35 | return $user[0]; |
||||
| 36 | } |
||||
| 37 | |||||
| 38 | /** |
||||
| 39 | * Display a listing of the resource. |
||||
| 40 | * |
||||
| 41 | * @return \Illuminate\Http\Response |
||||
| 42 | */ |
||||
| 43 | public function index() |
||||
| 44 | { |
||||
| 45 | $users = User::onlyTrashed()->get(); |
||||
| 46 | $roles = Role::all(); |
||||
| 47 | |||||
| 48 | return View('usersmanagement.show-deleted-users', compact('users', 'roles')); |
||||
|
0 ignored issues
–
show
|
|||||
| 49 | } |
||||
| 50 | |||||
| 51 | /** |
||||
| 52 | * Display the specified resource. |
||||
| 53 | * |
||||
| 54 | * @param int $id |
||||
| 55 | * |
||||
| 56 | * @return \Illuminate\Http\Response |
||||
| 57 | */ |
||||
| 58 | public function show($id) |
||||
| 59 | { |
||||
| 60 | $user = self::getDeletedUser($id); |
||||
| 61 | |||||
| 62 | return view('usersmanagement.show-deleted-user')->withUser($user); |
||||
|
0 ignored issues
–
show
|
|||||
| 63 | } |
||||
| 64 | |||||
| 65 | /** |
||||
| 66 | * Update the specified resource in storage. |
||||
| 67 | * |
||||
| 68 | * @param \Illuminate\Http\Request $request |
||||
| 69 | * @param int $id |
||||
| 70 | * |
||||
| 71 | * @return \Illuminate\Http\Response |
||||
| 72 | */ |
||||
| 73 | public function update(Request $request, $id) |
||||
|
0 ignored issues
–
show
The parameter
$request is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 74 | { |
||||
| 75 | $user = self::getDeletedUser($id); |
||||
| 76 | $user->restore(); |
||||
| 77 | |||||
| 78 | return redirect('/users/')->with('success', trans('usersmanagement.successRestore')); |
||||
|
0 ignored issues
–
show
|
|||||
| 79 | } |
||||
| 80 | |||||
| 81 | /** |
||||
| 82 | * Remove the specified resource from storage. |
||||
| 83 | * |
||||
| 84 | * @param int $id |
||||
| 85 | * |
||||
| 86 | * @return \Illuminate\Http\Response |
||||
| 87 | */ |
||||
| 88 | public function destroy($id) |
||||
| 89 | { |
||||
| 90 | $user = self::getDeletedUser($id); |
||||
| 91 | $user->forceDelete(); |
||||
| 92 | |||||
| 93 | return redirect('/users/deleted/')->with('success', trans('usersmanagement.successDestroy')); |
||||
|
0 ignored issues
–
show
|
|||||
| 94 | } |
||||
| 95 | } |
||||
| 96 |