Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
56.00% |
14 / 25 |
|
57.14% |
4 / 7 |
CRAP | |
0.00% |
0 / 1 |
| StaffController | |
56.00% |
14 / 25 |
|
57.14% |
4 / 7 |
13.45 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| index | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| create | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| edit | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| destroy | |
25.00% |
1 / 4 |
|
0.00% |
0 / 1 |
1.42 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\admin; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Http\Requests\Admin\StaffRequest; |
| 7 | use App\Models\User; |
| 8 | use App\Services\Permission\RoleService; |
| 9 | use App\Services\Permission\StaffService; |
| 10 | use Illuminate\Http\RedirectResponse; |
| 11 | use Illuminate\Http\Request; |
| 12 | use Illuminate\View\View; |
| 13 | |
| 14 | /** |
| 15 | * People → Staff. Add someone, give them a role, done. |
| 16 | */ |
| 17 | class StaffController extends Controller |
| 18 | { |
| 19 | public function __construct( |
| 20 | private StaffService $staff, |
| 21 | private RoleService $roles, |
| 22 | ) {} |
| 23 | |
| 24 | public function index(Request $request): View |
| 25 | { |
| 26 | return view('admin.staff.index', [ |
| 27 | 'staff' => $this->staff->list(trim((string) $request->input('search')) ?: null), |
| 28 | 'roles' => $this->roles->all(), |
| 29 | ]); |
| 30 | } |
| 31 | |
| 32 | public function create(): View |
| 33 | { |
| 34 | return view('admin.staff.form', [ |
| 35 | 'staff' => null, |
| 36 | 'roles' => $this->roles->all(), |
| 37 | ]); |
| 38 | } |
| 39 | |
| 40 | public function store(StaffRequest $request): RedirectResponse |
| 41 | { |
| 42 | $this->staff->create($request->validated()); |
| 43 | |
| 44 | return redirect() |
| 45 | ->route('admin.staff.index') |
| 46 | ->with('success', $request->input('name') . ' can now sign in.'); |
| 47 | } |
| 48 | |
| 49 | public function edit(User $user): View |
| 50 | { |
| 51 | return view('admin.staff.form', [ |
| 52 | 'staff' => $user->load('roles:id,name'), |
| 53 | 'roles' => $this->roles->all(), |
| 54 | ]); |
| 55 | } |
| 56 | |
| 57 | public function update(StaffRequest $request, User $user): RedirectResponse |
| 58 | { |
| 59 | $this->staff->update($user, $request->validated()); |
| 60 | |
| 61 | return redirect() |
| 62 | ->route('admin.staff.index') |
| 63 | ->with('success', $user->name . ' updated.'); |
| 64 | } |
| 65 | |
| 66 | public function destroy(User $user): RedirectResponse |
| 67 | { |
| 68 | $this->staff->delete($user); |
| 69 | |
| 70 | return redirect() |
| 71 | ->route('admin.staff.index') |
| 72 | ->with('success', 'Staff member removed.'); |
| 73 | } |
| 74 | } |