Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| UserController | |
0.00% |
0 / 25 |
|
0.00% |
0 / 7 |
110 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
12 | |||
| show | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| edit | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| destroy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Http\Requests\UserRequest; |
| 6 | use App\Models\User; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Illuminate\Http\Response; |
| 9 | use Illuminate\Support\Facades\DB; |
| 10 | use Illuminate\Support\Facades\Hash; |
| 11 | |
| 12 | class UserController extends Controller |
| 13 | { |
| 14 | /** |
| 15 | * Display a listing of the resource. |
| 16 | * |
| 17 | * @return Response |
| 18 | */ |
| 19 | public function index() |
| 20 | { |
| 21 | $data['users'] = User::query()->get(); |
| 22 | |
| 23 | return view('admin.user.index')->with($data); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Show the form for creating a new resource. |
| 28 | * |
| 29 | * @return Response |
| 30 | */ |
| 31 | public function create() |
| 32 | { |
| 33 | return view('admin.user.form'); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Store a newly created resource in storage. |
| 38 | * |
| 39 | * @param Request $request |
| 40 | * @return Response |
| 41 | */ |
| 42 | public function store(UserRequest $request) |
| 43 | { |
| 44 | $data = $request->validated(); |
| 45 | $data['status'] = $request->status == 'on' ? 1 : 0; |
| 46 | try { |
| 47 | DB::beginTransaction(); |
| 48 | $data['password'] = Hash::make($request->password); |
| 49 | User::query()->create($data); |
| 50 | DB::commit(); |
| 51 | |
| 52 | return redirect()->route('admin.user.index')->with('success', 'User Added Successfully'); |
| 53 | } catch (\Throwable $e) { |
| 54 | DB::rollBack(); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Display the specified resource. |
| 60 | * |
| 61 | * @param int $id |
| 62 | * @return Response |
| 63 | */ |
| 64 | public function show($id) |
| 65 | { |
| 66 | // |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Show the form for editing the specified resource. |
| 71 | * |
| 72 | * @param int $id |
| 73 | * @return Response |
| 74 | */ |
| 75 | public function edit(User $user) |
| 76 | { |
| 77 | $data['user'] = $user; |
| 78 | |
| 79 | return view('admin.user.form')->with($data); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Update the specified resource in storage. |
| 84 | * |
| 85 | * @param int $id |
| 86 | * @return Response |
| 87 | */ |
| 88 | public function update(Request $request, $id) |
| 89 | { |
| 90 | $data = $request->all(); |
| 91 | try { |
| 92 | $user = User::query()->findOrFail($id); |
| 93 | |
| 94 | DB::beginTransaction(); |
| 95 | $data['password'] = Hash::make($request->password); |
| 96 | $user->update($data); |
| 97 | DB::commit(); |
| 98 | |
| 99 | return redirect()->route('admin.user.index')->with('success', 'User Update Successfully'); |
| 100 | } catch (\Throwable $e) { |
| 101 | DB::rollBack(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Remove the specified resource from storage. |
| 107 | * |
| 108 | * @param int $id |
| 109 | * @return Response |
| 110 | */ |
| 111 | public function destroy($id) |
| 112 | { |
| 113 | // |
| 114 | } |
| 115 | } |