Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Category;
- use App\Type;
- use App\Offer;
- use App\Product;
- use DB;
- Use Session;
- class OffersController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index()
- {
- $offer=Offer::all();
- $productoffer = DB::table('offers')->join('product_is_offered','product_is_offered.offer_id','offers.id')
- ->join('products','products.id','product_is_offered.product_id')->get();
- $productoffer=$productoffer->reverse();
- return view('offer.index')->with('offers',$productoffer);
- }
- public function size(Request $request){
- $select=$request->get('select');
- $value=$request->get('value');
- $productsizeprice=DB::table('products')
- ->join('product_size_prices','product_size_prices.product_id','products.id')
- ->where('products.id',$value)
- ->get();
- // dd($productsizeprice);
- $output='<tr id="show-price">'
- .' <td>'.
- '</td>'
- .'<td>'.
- '</td>'
- .'<td>'.
- '</td>'
- .'</tr>';
- foreach($productsizeprice as $productsingleprice){
- $output.='<tr id="show-price">'
- .' <td >'
- .'<div class="col-sm-2">'
- . ' <input type="hidden" name="productid[]" value="'.$productsingleprice->product_id.'" class="form-control">'
- .'</div>'
- .
- '</td>'
- .' <td >'
- .'<div class="col-sm-2">'
- . ' <input type="hidden" name="sizepriceid[]" value="'.$productsingleprice->id.'" class="form-control">'
- .'</div>'
- .
- '</td>'
- .' <td>'
- .'<div class="col-sm-10">'
- . ' <input required type="text" name="productsinglesize[]" value="'.$productsingleprice->size.'" class="form-control">'
- .'</div>'
- .
- '</td>'.
- '<td>'
- .'<div class="col-sm-10">'
- . ' <input type="text" name="productsingleprice[]" value="'.$productsingleprice->price.'" class="form-control">'
- .'</div>'
- . '</td>'
- .'<td >'
- .'<div class="col-sm-10">'
- . ' <input type="text" name="productsinglequantity[]" value="'.$productsingleprice->quantity.'" class="form-control">'
- .'</div>'
- . '</td>'
- .'</tr>';
- }
- echo $output;
- }
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- return view('offer.create')->with('categories',Category::all())->with('types',Type::all())->with('products',Product::all());
- }
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- $offername=$request->offername;
- if ($offername==null){
- $offerid=$request->offerid;
- }
- else{
- $offerid = DB::table('offers')->insertGetId(
- ['offer_name' => $offername]
- );
- }
- $categoryid=$request->categoryid;
- $typeid=$request->typeid;
- $sizepriceid=$request->get('sizepriceidform');
- $productid=$request->get('productidform');
- // dd($productid);
- $priority=$request->get('priority');
- // $sizepricepriority = array_combine($sizepriceid, $priority);
- // dd($productid[0]);
- foreach ($sizepriceid as $key => $value) {
- // foreach ($productid as $key => $value1) {
- DB::table('product_is_offered')->insert(
- ['offer_id' => $offerid, 'product_size_price_id' => $value,'category_id' => $categoryid,'type_id' => $typeid,'priority' => $priority[$key],'product_id'=>$productid[$key]]
- );
- // }
- }
- return redirect()->route('offers');
- }
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- //
- }
- public function modalsubmit(Request $request){
- $value=$request->nameinput111;
- // $productid=$request->get('productid');
- // dd($productid);
- $productidform=$request->get('productid');
- $sizepriceid=$request->get('sizepriceid');
- // $productid=DB::table('product_size_prices')->select('product_id')->where('id',5)->first();
- // dd($productid->product_id);
- $size=$request->get('productsinglesize');
- $price=$request->get('productsingleprice');
- $quantity=$request->get('productsinglequantity');
- if((count($sizepriceid))>=1){
- foreach ($sizepriceid as $key => $value) {
- $productjoinsize=DB::table('product_size_prices')
- ->join('products','products.id','product_size_prices.product_id')
- ->select('*')->where('product_size_prices.id',$sizepriceid[$key])->first();
- // dd($productid);
- // dd($productjoinsize);
- if($sizepriceid[$key]=="false"){
- // dd($price[$key]);
- // dd("ggg");
- dd($productid[$key]);
- $productid=DB::table('product_size_prices')->select('product_id')->where('id',$sizepriceid[$key])->first();
- dd($productid->id);
- $sizepriceidd=DB::table('product_size_prices')->insert(
- ['size' => $size[$key], 'price' => $price[$key],'quantity'=>$quantity[$key],'product_id'=>10]
- );
- dd("hhh");
- }
- else{
- // $sizepriceidd=DB::table('product_size_prices')->insertGetId(
- // ['size' => $size[$key], 'price' => $price[$key],'quantity'=>$quantity[$key],'product_id'=>10]
- // );
- }
- // dd();
- $output='<tr>'
- .'<td>'.
- $productjoinsize->productName.
- '</td>'
- .'<td>'
- .$size[$key]
- .'</td>'.
- '<td>'.
- $price[$key].
- '</td>'.
- '<td>'
- .$quantity[$key].
- '</td>'.
- '<td>'
- .'<input type="text" name="priority[]" value="">'.
- '</td>'
- .' <td >'.
- '<input type="hidden" name="sizepriceidform[]" value="'.$sizepriceid[$key].'">'.
- '</td>'
- .' <td >'.
- '<input type="hidden" name="productidform[]" value="'.$productidform[$key].'">'.
- '</td>'
- .'</tr>';
- echo $output;
- }
- }
- // dd($quantity);
- $value=$request->get('nameinput111');
- $productid=$request->get('product_name');
- $productname=Product::find($productid);
- // DB::table('product_size_prices')
- // ->where('product_id',$productid)
- // ->update(
- // ['quantity' => $quantity]
- //);
- // $output='<tr>'
- // .' <td>'.
- // '</td>'
- // .'<td>'.
- // '</td>'
- // .'</tr>';
- // $output='<tr>'
- // .'<td>'.
- // $productname->productName.
- // '</td>'.
- // '<td>'
- // .'<input type="text" name="priority[]" value="">'.
- //
- // '</td>'
- // .' <td >'.
- // '<input type="hidden" name="idfrompop[]" value="'.$productname->id.'">'.
- // '</td>'
- // .'</tr>';
- //
- // echo $output;
- }
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit()
- {
- return view('offer.update')->with('offers',Offer::all())->with('categories',Category::all())->with('types',Type::all())->with('products',Product::all());
- }
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request)
- {
- return view('offer.update')->with('offers',Offer::all())->with('categories',Category::all())->with('types',Type::all())->with('products',Product::all());
- }
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement