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