Completed
Push — master ( c76df9...ef3d70 )
by Jeff
18:25
created

BrandController::store()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Admin\Brands;
4
5
use App\Http\Controllers\Controller;
6
use App\Shop\Brands\Repositories\BrandRepositoryInterface;
7
use App\Shop\Brands\Requests\CreateBrandRequest;
8
use App\Shop\Brands\Requests\UpdateBrandRequest;
9
10
class BrandController extends Controller
11
{
12
    /**
13
     * @var BrandRepositoryInterface
14
     */
15
    private $brandRepo;
16
17
    /**
18
     * BrandController constructor.
19
     *
20
     * @param BrandRepositoryInterface $brandRepository
21
     */
22
    public function __construct(BrandRepositoryInterface $brandRepository)
23
    {
24
        $this->brandRepo = $brandRepository;
25
    }
26
27
    /**
28
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
29
     */
30
    public function index()
31
    {
32
        $data = $this->brandRepo->paginateArrayResults($this->brandRepo->listBrands()->all());
33
34
        return view('admin.brands.list', ['brands' => $data]);
35
    }
36
37
    /**
38
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
39
     */
40
    public function create()
41
    {
42
        return view('admin.brands.create');
43
    }
44
45
    /**
46
     * @param CreateBrandRequest $request
47
     *
48
     * @return \Illuminate\Http\RedirectResponse
49
     */
50
    public function store(CreateBrandRequest $request)
51
    {
52
        $this->brandRepo->createBrand($request->all());
53
54
        return redirect()->route('admin.brands.index')->with('message', 'Create brand successful!');
55
    }
56
57
    /**
58
     * @param $id
59
     *
60
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
61
     */
62
    public function edit($id)
63
    {
64
        return view('admin.brands.edit', ['brand' => $this->brandRepo->findBrandById($id)]);
65
    }
66
67
    /**
68
     * @param UpdateBrandRequest $request
69
     * @param $id
70
     *
71
     * @return \Illuminate\Http\RedirectResponse
72
     */
73
    public function update(UpdateBrandRequest $request, $id)
74
    {
75
        $this->brandRepo->updateBrand($request->all(), $id);
76
77
        return redirect()->route('admin.brands.edit', $id)->with('message', 'Update successful!');
78
    }
79
80
    /**
81
     * @param $id
82
     *
83
     * @return \Illuminate\Http\RedirectResponse
84
     */
85
    public function destroy($id)
86
    {
87
        $this->brandRepo->deleteBrand($id);
88
89
        return redirect()->route('admin.brands.index')->with('message', 'Delete successful!');
90
    }
91
}