Advertisement
Guest User

demo2

a guest
Oct 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Category;
  7. use App\Type;
  8. use App\Offer;
  9. use App\Product;
  10. use DB;
  11. Use Session;
  12.  
  13. class OffersController extends Controller
  14. {
  15. /**
  16. * Display a listing of the resource.
  17. *
  18. * @return \Illuminate\Http\Response
  19. */
  20. public function index()
  21. {
  22. $offer=Offer::all();
  23. $productoffer = DB::table('offers')->join('product_is_offered','product_is_offered.offer_id','offers.id')
  24. ->join('products','products.id','product_is_offered.product_id')->get();
  25. $productoffer=$productoffer->reverse();
  26. return view('offer.index')->with('offers',$productoffer);
  27. }
  28. public function size(Request $request){
  29. $select=$request->get('select');
  30. $value=$request->get('value');
  31.  
  32. $productsizeprice=DB::table('products')
  33. ->join('product_size_prices','product_size_prices.product_id','products.id')
  34. ->where('products.id',$value)
  35. ->get();
  36. // dd($productsizeprice);
  37.  
  38. $output='<tr id="show-price">'
  39. .' <td>'.
  40.  
  41. '</td>'
  42. .'<td>'.
  43.  
  44.  
  45. '</td>'
  46. .'<td>'.
  47.  
  48.  
  49. '</td>'
  50.  
  51. .'</tr>';
  52. foreach($productsizeprice as $productsingleprice){
  53. $output.='<tr id="show-price">'
  54. .' <td >'
  55.  
  56. .'<div class="col-sm-2">'
  57. . ' <input type="hidden" name="productid[]" value="'.$productsingleprice->product_id.'" class="form-control">'
  58. .'</div>'
  59. .
  60. '</td>'
  61.  
  62. .' <td >'
  63.  
  64. .'<div class="col-sm-2">'
  65. . ' <input type="hidden" name="sizepriceid[]" value="'.$productsingleprice->id.'" class="form-control">'
  66. .'</div>'
  67. .
  68. '</td>'
  69. .' <td>'
  70.  
  71. .'<div class="col-sm-10">'
  72. . ' <input required type="text" name="productsinglesize[]" value="'.$productsingleprice->size.'" class="form-control">'
  73. .'</div>'
  74. .
  75. '</td>'.
  76. '<td>'
  77. .'<div class="col-sm-10">'
  78. . ' <input type="text" name="productsingleprice[]" value="'.$productsingleprice->price.'" class="form-control">'
  79. .'</div>'
  80.  
  81. . '</td>'
  82. .'<td >'
  83. .'<div class="col-sm-10">'
  84. . ' <input type="text" name="productsinglequantity[]" value="'.$productsingleprice->quantity.'" class="form-control">'
  85. .'</div>'
  86.  
  87. . '</td>'
  88.  
  89. .'</tr>';
  90. }
  91. echo $output;
  92. }
  93.  
  94. /**
  95. * Show the form for creating a new resource.
  96. *
  97. * @return \Illuminate\Http\Response
  98. */
  99. public function create()
  100. {
  101. return view('offer.create')->with('categories',Category::all())->with('types',Type::all())->with('products',Product::all());
  102. }
  103.  
  104. /**
  105. * Store a newly created resource in storage.
  106. *
  107. * @param \Illuminate\Http\Request $request
  108. * @return \Illuminate\Http\Response
  109. */
  110. public function store(Request $request)
  111. {
  112. $offername=$request->offername;
  113. if ($offername==null){
  114. $offerid=$request->offerid;
  115. }
  116. else{
  117. $offerid = DB::table('offers')->insertGetId(
  118. ['offer_name' => $offername]
  119. );
  120. }
  121. $categoryid=$request->categoryid;
  122. $typeid=$request->typeid;
  123.  
  124. $sizepriceid=$request->get('sizepriceidform');
  125. $productid=$request->get('productidform');
  126. // dd($productid);
  127. $priority=$request->get('priority');
  128. // $sizepricepriority = array_combine($sizepriceid, $priority);
  129. // dd($productid[0]);
  130. foreach ($sizepriceid as $key => $value) {
  131. // foreach ($productid as $key => $value1) {
  132.  
  133.  
  134. DB::table('product_is_offered')->insert(
  135. ['offer_id' => $offerid, 'product_size_price_id' => $value,'category_id' => $categoryid,'type_id' => $typeid,'priority' => $priority[$key],'product_id'=>$productid[$key]]
  136. );
  137. // }
  138. }
  139.  
  140. return redirect()->route('offers');
  141.  
  142. }
  143.  
  144. /**
  145. * Display the specified resource.
  146. *
  147. * @param int $id
  148. * @return \Illuminate\Http\Response
  149. */
  150. public function show($id)
  151. {
  152. //
  153. }
  154. public function modalsubmit(Request $request){
  155. $value=$request->nameinput111;
  156. // $productid=$request->get('productid');
  157. // dd($productid);
  158. $productidform=$request->get('productid');
  159. $sizepriceid=$request->get('sizepriceid');
  160. // $productid=DB::table('product_size_prices')->select('product_id')->where('id',5)->first();
  161. // dd($productid->product_id);
  162. $size=$request->get('productsinglesize');
  163. $price=$request->get('productsingleprice');
  164. $quantity=$request->get('productsinglequantity');
  165. if((count($sizepriceid))>=1){
  166. foreach ($sizepriceid as $key => $value) {
  167. $productjoinsize=DB::table('product_size_prices')
  168. ->join('products','products.id','product_size_prices.product_id')
  169. ->select('*')->where('product_size_prices.id',$sizepriceid[$key])->first();
  170. // dd($productid);
  171. // dd($productjoinsize);
  172. if($sizepriceid[$key]=="false"){
  173. // dd($price[$key]);
  174. // dd("ggg");
  175. dd($productid[$key]);
  176. $productid=DB::table('product_size_prices')->select('product_id')->where('id',$sizepriceid[$key])->first();
  177. dd($productid->id);
  178. $sizepriceidd=DB::table('product_size_prices')->insert(
  179. ['size' => $size[$key], 'price' => $price[$key],'quantity'=>$quantity[$key],'product_id'=>10]
  180. );
  181.  
  182. dd("hhh");
  183. }
  184. else{
  185. // $sizepriceidd=DB::table('product_size_prices')->insertGetId(
  186. // ['size' => $size[$key], 'price' => $price[$key],'quantity'=>$quantity[$key],'product_id'=>10]
  187. // );
  188. }
  189. // dd();
  190. $output='<tr>'
  191. .'<td>'.
  192. $productjoinsize->productName.
  193. '</td>'
  194. .'<td>'
  195. .$size[$key]
  196. .'</td>'.
  197. '<td>'.
  198. $price[$key].
  199. '</td>'.
  200.  
  201. '<td>'
  202. .$quantity[$key].
  203. '</td>'.
  204. '<td>'
  205. .'<input type="text" name="priority[]" value="">'.
  206.  
  207. '</td>'
  208. .' <td >'.
  209. '<input type="hidden" name="sizepriceidform[]" value="'.$sizepriceid[$key].'">'.
  210. '</td>'
  211. .' <td >'.
  212. '<input type="hidden" name="productidform[]" value="'.$productidform[$key].'">'.
  213. '</td>'
  214.  
  215. .'</tr>';
  216.  
  217. echo $output;
  218.  
  219.  
  220. }
  221. }
  222.  
  223. // dd($quantity);
  224. $value=$request->get('nameinput111');
  225. $productid=$request->get('product_name');
  226. $productname=Product::find($productid);
  227.  
  228. // DB::table('product_size_prices')
  229. // ->where('product_id',$productid)
  230. // ->update(
  231. // ['quantity' => $quantity]
  232. //);
  233.  
  234. // $output='<tr>'
  235. // .' <td>'.
  236.  
  237. // '</td>'
  238. // .'<td>'.
  239.  
  240.  
  241. // '</td>'
  242.  
  243. // .'</tr>';
  244.  
  245. // $output='<tr>'
  246. // .'<td>'.
  247. // $productname->productName.
  248. // '</td>'.
  249. // '<td>'
  250. // .'<input type="text" name="priority[]" value="">'.
  251. //
  252. // '</td>'
  253. // .' <td >'.
  254. // '<input type="hidden" name="idfrompop[]" value="'.$productname->id.'">'.
  255. // '</td>'
  256. // .'</tr>';
  257. //
  258. // echo $output;
  259. }
  260.  
  261.  
  262. /**
  263. * Show the form for editing the specified resource.
  264. *
  265. * @param int $id
  266. * @return \Illuminate\Http\Response
  267. */
  268. public function edit()
  269. {
  270. return view('offer.update')->with('offers',Offer::all())->with('categories',Category::all())->with('types',Type::all())->with('products',Product::all());
  271. }
  272.  
  273. /**
  274. * Update the specified resource in storage.
  275. *
  276. * @param \Illuminate\Http\Request $request
  277. * @param int $id
  278. * @return \Illuminate\Http\Response
  279. */
  280. public function update(Request $request)
  281. {
  282. return view('offer.update')->with('offers',Offer::all())->with('categories',Category::all())->with('types',Type::all())->with('products',Product::all());
  283. }
  284.  
  285.  
  286. /**
  287. * Remove the specified resource from storage.
  288. *
  289. * @param int $id
  290. * @return \Illuminate\Http\Response
  291. */
  292. public function destroy($id)
  293. {
  294. //
  295. }
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement