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