Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 41 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| SectionController | |
0.00% |
0 / 41 |
|
0.00% |
0 / 7 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| index | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| show | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| edit | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
6 | |||
| destroy | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\Section; |
| 6 | use App\Repository\ConfigurationRepository; |
| 7 | use App\Service\TableName; |
| 8 | use App\Traits\PosTrait; |
| 9 | use Illuminate\Http\Request; |
| 10 | use Illuminate\Http\Response; |
| 11 | use Illuminate\Support\Facades\DB; |
| 12 | use Illuminate\Support\Str; |
| 13 | use Illuminate\Validation\Rule; |
| 14 | |
| 15 | class SectionController extends Controller |
| 16 | { |
| 17 | use PosTrait; |
| 18 | |
| 19 | protected $repository; |
| 20 | |
| 21 | public function __construct(ConfigurationRepository $repository) |
| 22 | { |
| 23 | $this->repository = $repository; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Display a listing of the resource. |
| 28 | * |
| 29 | * @return Response |
| 30 | */ |
| 31 | public function index() |
| 32 | { |
| 33 | $data['sections'] = Section::query()->orderBy('position', 'ASC')->get(); |
| 34 | |
| 35 | return view('admin.configuration.section')->with($data); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Store a newly created resource in storage. |
| 40 | * |
| 41 | * @return Response |
| 42 | */ |
| 43 | public function store(Request $request) |
| 44 | { |
| 45 | $data['request'] = $request->validate([ |
| 46 | 'name' => ['required', Rule::unique('sections')], |
| 47 | 'title' => 'nullable', |
| 48 | 'position' => 'nullable', |
| 49 | 'status' => 'nullable', |
| 50 | ]); |
| 51 | |
| 52 | try { |
| 53 | DB::beginTransaction(); |
| 54 | $table_name = TableName::SECTION; |
| 55 | $section = $this->repository::storeConfig($table_name, $data); |
| 56 | DB::commit(); |
| 57 | |
| 58 | return redirect()->back()->with('success', 'Section Successfully Inserted'); |
| 59 | } catch (\Throwable $e) { |
| 60 | DB::rollBack(); |
| 61 | report($e); |
| 62 | |
| 63 | return back()->withInput()->with('error', 'Could not save the section.'); |
| 64 | } |
| 65 | |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Display the specified resource. |
| 70 | * |
| 71 | * @param int $id |
| 72 | * @return Response |
| 73 | */ |
| 74 | public function show($id) |
| 75 | { |
| 76 | return 'hello data'; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Show the form for editing the specified resource. |
| 81 | * |
| 82 | * @param int $id |
| 83 | * @return Response |
| 84 | */ |
| 85 | public function edit($id) |
| 86 | { |
| 87 | $data['section'] = Section::findById($id); |
| 88 | $data['sections'] = Section::getAll(); |
| 89 | |
| 90 | return view('admin.configuration.section')->with($data); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Update the specified resource in storage. |
| 95 | * |
| 96 | * @param int $id |
| 97 | * @return Response |
| 98 | */ |
| 99 | public function update(Request $request, $id) |
| 100 | { |
| 101 | $data = $request->validate([ |
| 102 | 'name' => ['required', Rule::unique('sections')->ignore($id)], |
| 103 | 'title' => 'nullable', |
| 104 | 'position' => 'nullable', |
| 105 | 'status' => 'nullable', |
| 106 | ]); |
| 107 | |
| 108 | try { |
| 109 | DB::beginTransaction(); |
| 110 | |
| 111 | $section = Section::findById($id); |
| 112 | |
| 113 | $data['slug'] = Str::slug($request->name); |
| 114 | |
| 115 | $section->update($data); |
| 116 | |
| 117 | DB::commit(); |
| 118 | |
| 119 | return redirect()->route('admin.sections.index')->with('success', 'Section Successfully Updated'); |
| 120 | } catch (\Throwable $e) { |
| 121 | DB::rollBack(); |
| 122 | report($e); |
| 123 | |
| 124 | return back()->withInput()->with('error', 'Could not update the section.'); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Remove the specified resource from storage. |
| 130 | * |
| 131 | * @param int $id |
| 132 | * @return Response |
| 133 | */ |
| 134 | public function destroy($id) |
| 135 | { |
| 136 | $section = Section::findOrFail($id); |
| 137 | $section->delete(); |
| 138 | |
| 139 | return redirect()->back()->with('success', 'Section Deleted Successfully'); |
| 140 | } |
| 141 | } |