Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| FeedsController | |
0.00% |
0 / 28 |
|
0.00% |
0 / 8 |
90 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| show | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| edit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| destroy | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| toggle | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\Feed; |
| 6 | use App\Http\Requests\StoreFeedRequest; |
| 7 | use App\Http\Requests\UpdateFeedRequest; |
| 8 | use App\Services\OnboardingRedirectService; |
| 9 | use Illuminate\Contracts\View\View; |
| 10 | use Illuminate\Http\RedirectResponse; |
| 11 | |
| 12 | class FeedsController extends Controller |
| 13 | { |
| 14 | public function index(): View |
| 15 | { |
| 16 | $feeds = Feed::orderBy('is_active', 'desc') |
| 17 | ->orderBy('name') |
| 18 | ->get(); |
| 19 | |
| 20 | return view('pages.feeds.index', compact('feeds')); |
| 21 | } |
| 22 | |
| 23 | public function create(): View |
| 24 | { |
| 25 | return view('pages.feeds.create'); |
| 26 | } |
| 27 | |
| 28 | public function store(StoreFeedRequest $request): RedirectResponse |
| 29 | { |
| 30 | $validated = $request->validated(); |
| 31 | $validated['is_active'] = $validated['is_active'] ?? true; |
| 32 | |
| 33 | Feed::create($validated); |
| 34 | |
| 35 | return OnboardingRedirectService::handleRedirect( |
| 36 | $request, |
| 37 | 'feeds.index', |
| 38 | 'Feed created successfully!' |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | public function show(Feed $feed): View |
| 43 | { |
| 44 | return view('pages.feeds.show', compact('feed')); |
| 45 | } |
| 46 | |
| 47 | public function edit(Feed $feed): View |
| 48 | { |
| 49 | return view('pages.feeds.edit', compact('feed')); |
| 50 | } |
| 51 | |
| 52 | public function update(UpdateFeedRequest $request, Feed $feed): RedirectResponse |
| 53 | { |
| 54 | $validated = $request->validated(); |
| 55 | $validated['is_active'] = $validated['is_active'] ?? $feed->is_active; |
| 56 | |
| 57 | $feed->update($validated); |
| 58 | |
| 59 | return redirect()->route('feeds.index') |
| 60 | ->with('success', 'Feed updated successfully!'); |
| 61 | } |
| 62 | |
| 63 | public function destroy(Feed $feed): RedirectResponse |
| 64 | { |
| 65 | $feed->delete(); |
| 66 | |
| 67 | return redirect()->route('feeds.index') |
| 68 | ->with('success', 'Feed deleted successfully!'); |
| 69 | } |
| 70 | |
| 71 | public function toggle(Feed $feed): RedirectResponse |
| 72 | { |
| 73 | $newStatus = !$feed->is_active; |
| 74 | $feed->update(['is_active' => $newStatus]); |
| 75 | |
| 76 | $status = $newStatus ? 'activated' : 'deactivated'; |
| 77 | |
| 78 | return redirect()->route('feeds.index') |
| 79 | ->with('success', "Feed {$status} successfully!"); |
| 80 | } |
| 81 | } |