Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
CategoryController
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 6
72
0.00% covered (danger)
0.00%
0 / 1
 index
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 create
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 store
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
 edit
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 update
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 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\Dashboard;
4
5use App\Http\Controllers\Controller;
6use App\Models\Category;
7use App\Models\CategoryTranslation;
8use Illuminate\Http\Request;
9use Illuminate\Support\Facades\DB;
10
11class CategoryController extends Controller
12{
13    public function index(){
14        $categories = Category::tree()->get();
15        return view('Dashboard.categories.index')->with([
16            'categories'    => $categories,
17        ]);
18    }
19
20    public function create(){
21        $categories = Category::tree(0)->get();
22
23        return view('Dashboard.categories.create')->with([
24            'categories'    => $categories,
25        ]);
26    }
27
28    public function store(Request $request){
29        try{
30            DB::beginTransaction();
31                $input = $request->only('parent_id', 'en', 'ar');
32
33                Category::create($input);
34            DB::commit();
35            return redirect('dashboard/categories')->with('success', 'success');
36        } catch(\Exception $ex){
37            return $ex;
38            return redirect('dashboard/categories')->with('error', 'faild');
39        }
40    }
41
42    public function edit($id){
43        $data = Category::findOrFail($id);
44        $categories = Category::tree(0)->where('id', '!=',$id)->get();
45
46        return view('Dashboard.categories.edit')->with([
47            'categories'    => $categories,
48            'data'  => $data,
49        ]);
50    }
51
52    public function update(Request $request, $id){
53        $input = $request->only('parent_id', 'en', 'ar');
54        $category = Category::findOrFail($id);
55
56        try{
57            DB::beginTransaction();
58                $category->update($input);
59            DB::commit();
60            return redirect('dashboard/categories')->with('success', 'success');
61        } catch(\Exception $ex){
62            return redirect('dashboard/categories')->with('error', 'faild');
63        }
64    }
65
66    public function destroy($id){
67        $category = Category::findOrFail($id);
68        $category->delete();
69        return redirect('dashboard/categories')->with('success', 'success');
70    }
71}