6
6
use App \products ;
7
7
use Illuminate \Http \Request ;
8
8
use Storage ;
9
+ use App \pro_cat ;
9
10
10
11
class AdminController extends Controller {
11
12
@@ -31,27 +32,135 @@ public function add_product(Request $request) {
31
32
$ products ->spl_price = $ request ->spl_price ;
32
33
$ products ->pro_img = $ filename ;
33
34
$ products ->save ();
34
-
35
+
35
36
$ cat_data = DB ::table ('pro_cat ' )->get ();
36
37
37
38
return view ('admin.home ' , compact ('cat_data ' ));
38
-
39
+
39
40
// return redirect()->action('AdminController@index')->with('status', 'Product Uploaded!');
40
41
}
41
-
42
- public function view_products () {
43
-
44
- return view ('admin.products ' );
45
- }
46
-
47
- public function add_cat () {
48
-
49
- return view ('admin.addCat ' );
50
- }
51
-
52
- public function view_cats () {
53
-
54
- return view ('admin.categories ' );
55
- }
56
42
43
+ public function view_products () {
44
+
45
+ $ Products = DB ::table ('pro_cat ' )->rightJoin ('products ' , 'products.cat_id ' , '= ' , 'pro_cat.id ' )->get (); // now we are fetching all products
46
+
47
+
48
+ return view ('admin.products ' , compact ('Products ' ));
49
+ }
50
+
51
+ public function add_cat () {
52
+
53
+ return view ('admin.addCat ' );
54
+ }
55
+
56
+ // add cat
57
+ public function catForm (Request $ request ) {
58
+ //echo $request->cat_name;
59
+ //return 'update query here';
60
+ $ pro_cat = new pro_cat ;
61
+
62
+ $ pro_cat ->name = $ request ->cat_name ;
63
+ $ pro_cat ->status = '0 ' ; // by defalt enable
64
+ $ pro_cat ->save ();
65
+
66
+ $ cats = DB ::table ('pro_cat ' )->orderby ('id ' , 'DESC ' )->get ();
67
+
68
+ return view ('admin.categories ' , compact ('cats ' ));
69
+ }
70
+
71
+ // edit form for cat
72
+ public function CatEditForm (Request $ request ) {
73
+ $ catid = $ request ->id ;
74
+ $ cats = DB ::table ('pro_cat ' )->where ('id ' , $ catid )->get ();
75
+ return view ('admin.CatEditForm ' , compact ('cats ' ));
76
+ }
77
+
78
+ //update query to edit cat
79
+ public function editCat (Request $ request ) {
80
+
81
+ $ catid = $ request ->id ;
82
+ $ catName = $ request ->cat_name ;
83
+ $ status = $ request ->status ;
84
+ DB ::table ('pro_cat ' )->where ('id ' , $ catid )->update (['name ' => $ catName , 'status ' => $ status ]);
85
+
86
+ $ cats = DB ::table ('pro_cat ' )->orderby ('id ' , 'DESC ' )->get ();
87
+
88
+ return view ('admin.categories ' , compact ('cats ' ));
89
+ }
90
+
91
+ public function view_cats () {
92
+
93
+ $ cats = DB ::table ('pro_cat ' )->get ();
94
+
95
+ return view ('admin.categories ' , compact ('cats ' ));
96
+ }
97
+
98
+ public function ProductEditForm ($ id ) {
99
+ //$pro_id = $reqeust->id;
100
+ $ Products = DB ::table ('products ' )->where ('id ' , '= ' , $ id )->get (); // now we are fetching all products
101
+ return view ('admin.editPproducts ' , compact ('Products ' ));
102
+ }
103
+
104
+ public function editProduct (Request $ request ) {
105
+
106
+ $ proid = $ request ->id ;
107
+
108
+ $ pro_name = $ request ->pro_name ;
109
+ $ cat_id = $ request ->cat_id ;
110
+ $ pro_code = $ request ->pro_code ;
111
+ $ pro_price = $ request ->pro_price ;
112
+ $ pro_info = $ request ->pro_info ;
113
+ $ spl_price = $ request ->spl_price ;
114
+
115
+ DB ::table ('products ' )->where ('id ' , $ proid )->update ([
116
+ 'pro_name ' => $ pro_name ,
117
+ 'cat_id ' => $ cat_id ,
118
+ 'pro_code ' => $ pro_code ,
119
+ 'pro_price ' => $ pro_price ,
120
+ 'pro_info ' => $ pro_info ,
121
+ 'spl_price ' => $ spl_price ,
122
+ ]);
123
+
124
+
125
+ return redirect ('/admin/products ' );
126
+ //$Products = DB::table('pro_cat')->rightJoin('products','products.cat_id', '=', 'pro_cat.id')->get(); // now we are fetching all products
127
+ //return view('admin.products', compact('Products'));
128
+ }
129
+
130
+ public function ImageEditForm ($ id ) {
131
+ $ Products = DB ::table ('products ' )->where ('id ' , '= ' , $ id )->get (); // now we are fetching all products
132
+ return view ('admin.ImageEditForm ' , compact ('Products ' ));
133
+ }
134
+
135
+ public function editProImage (Request $ request ) {
136
+
137
+ $ proid = $ request ->id ;
138
+
139
+ $ file = $ request ->file ('new_image ' );
140
+ $ filename = $ file ->getClientOriginalName ();
141
+
142
+ $ path = 'upload/images ' ;
143
+ $ file ->move ($ path , $ filename );
144
+
145
+
146
+ DB ::table ('products ' )->where ('id ' , $ proid )->update (['pro_img ' => $ filename ]);
147
+
148
+ //echo 'done';
149
+ $ Products = DB ::table ('products ' )->get (); // now we are fetching all products
150
+ return view ('admin.products ' , compact ('Products ' ));
151
+ }
152
+
153
+ //for delete cat
154
+ public function deleteCat ($ id ) {
155
+
156
+ //echo $id;
157
+ DB ::table ('pro_cat ' )->where ('id ' , '= ' , $ id )->delete ();
158
+
159
+
160
+ $ cats = DB ::table ('pro_cat ' )->get ();
161
+
162
+ return view ('admin.categories ' , compact ('cats ' ));
163
+ }
164
+
165
+ // displaying cats in edit form of products
57
166
}
0 commit comments