lundi 21 octobre 2019

Laravel create dynamic Controller based on table columns

I need to have a product controller that is dynamic depending on the table. example I have two product table with different price points.

 public function store(Request $request)
    {
      $validatedData = $request->validate([
        'code' => 'required|max:255',
        'name' => 'required',
        'description' => 'required',
        'cost' => 'required',
        'price15' => 'required',
        'price25' => 'required',
        'price35' => 'required',
        'barcode' => 'required',
      ]);
      $product = new Product();
      $product->fun_product_code = $request['code'];
      $product->fun_product_name = $request['name'];
      $product->fun_product_desc = $request['description'];
      $product->fun_price_cost = (double)$request['cost'];
      $product->fun_price_10 = (double)$request['price10'];
      $product->fun_price_15 = (double)$request['price15'];
      $product->fun_price_25 = (double)$request['price25'];
      $product->fun_price_30 = (double)$request['price30'];
      $product->fun_price_35 = (double)$request['price35'];
      $product->fun_barcode = $request['barcode'];
      $product->save();
      return redirect('/productlist');
    }

How can I dynamically add these columns because one table only has price 10 and price 25 and the other as all?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire