Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 37 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| PaymentTypeController | |
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\PaymentType; |
| 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\DB; |
| 17 | use Illuminate\Support\Facades\File; |
| 18 | use Illuminate\Validation\Rule; |
| 19 | |
| 20 | class PaymentTypeController extends Controller |
| 21 | { |
| 22 | use PosTrait; |
| 23 | |
| 24 | protected $repository; |
| 25 | |
| 26 | public function __construct(ConfigurationRepository $repository) |
| 27 | { |
| 28 | $this->repository = $repository; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Display a listing of the resource. |
| 33 | * |
| 34 | * @return Application|Factory|View |
| 35 | */ |
| 36 | public function index() |
| 37 | { |
| 38 | $data['paymentTypes'] = PaymentType::query()->get(); |
| 39 | |
| 40 | return view('admin.configuration.paymentType')->with($data); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Store a newly created resource in storage. |
| 45 | * |
| 46 | * @param Request $request |
| 47 | * @return RedirectResponse |
| 48 | */ |
| 49 | public function store(ConfigurationRequest $request) |
| 50 | { |
| 51 | $data['request'] = $request->validated(); |
| 52 | try { |
| 53 | DB::beginTransaction(); |
| 54 | $table_name = 'PaymentType'; |
| 55 | $this->repository::storeConfig($table_name, $data); |
| 56 | DB::commit(); |
| 57 | |
| 58 | return redirect()->back()->with('success', 'PaymentType Successfully Inserted'); |
| 59 | } catch (\Throwable $e) { |
| 60 | DB::rollBack(); |
| 61 | report($e); |
| 62 | |
| 63 | return back()->withInput()->with('error', 'Could not save the payment type.'); |
| 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['paymentType'] = PaymentType::findOrFail($id); |
| 88 | $data['paymentTypes'] = PaymentType::query()->get(); |
| 89 | |
| 90 | return view('admin.configuration.paymentType')->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'] = $request->validate([ |
| 102 | 'name' => ['required', 'string', 'max:100', Rule::unique('payment_types')->ignore($id)], |
| 103 | 'description' => ['nullable', 'string', 'max:500'], |
| 104 | 'thumbnail' => ['nullable', 'image', 'max:2048'], |
| 105 | ]); |
| 106 | try { |
| 107 | DB::beginTransaction(); |
| 108 | $table_name = 'PaymentType'; |
| 109 | PaymentType::findOrFail($id)->update($data['request']); |
| 110 | DB::commit(); |
| 111 | |
| 112 | return redirect()->route('admin.paymentType.index')->with('success', 'PaymentType Successfully Updated'); |
| 113 | } catch (\Throwable $e) { |
| 114 | DB::rollBack(); |
| 115 | report($e); |
| 116 | |
| 117 | return back()->withInput()->with('error', 'Could not update the payment type.'); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Remove the specified resource from storage. |
| 123 | * |
| 124 | * @param int $id |
| 125 | * @return Response |
| 126 | */ |
| 127 | public function destroy($id) |
| 128 | { |
| 129 | $paymentType = PaymentType::findOrFail($id); |
| 130 | $paymentTypeImage = $paymentType->thumbnail; |
| 131 | if (file_exists($paymentTypeImage)) { |
| 132 | File::Delete($paymentTypeImage); |
| 133 | } |
| 134 | $paymentType->delete(); |
| 135 | |
| 136 | return redirect()->back()->with('delete', 'PaymentType Deleted Successfully'); |
| 137 | } |
| 138 | } |