public function addTruckUser(Request $request) { $token = $request->get('_token'); if ($token != '') { try { // data about truc $nametruck = date('dmY'); $from = $request->get('from'); $to = $request->get('to'); $description = $request->get('description'); $unit = $request->get('unit'); $created_at = date('Y-m-d H:i:s'); $address_detail_from = $request->get('address_detail_from'); $phone_number_from = $request->get('phone_number_from'); $email_from = $request->get('email_from'); $email_to = $request->get('email_to'); $address_detail_to = $request->get('address_detail_to'); $phone_number_to = $request->get('phone_number_to'); $data = array('nametruck' => 'X' . $nametruck, 'from_place' => $from, 'to_place' => $to, 'unit' => $unit, 'description' => $description, 'created_at' => $created_at, 'address_detail_to' => $address_detail_to, 'phone_to' => $phone_number_to, 'email_to' => $email_to, 'addresst_detail_from' => $address_detail_from, 'phone_from' => $phone_number_from, 'email_from' => $email_from); $id_truck = Truck::getInstance()->insert($data); // data for user $id_user = Session::get('user')->id; $input = array('user_id' => $id_user, 'custome_id' => $id_truck, 'type' => 'truck', 'status' => 'enable', 'created_at' => date('Y-m-d h:i:s')); $id_relation = Relation::getInstance()->insert($input); if ($id_relation) { return response()->json(array('message' => 'Lưu dữ liệu thành công!', 'error' => 0)); } else { return response()->json(array('message' => 'Lưu dữ liệu không thành công!', 'error' => 1)); } } catch (\Exception $e) { return response()->json(array('message' => 'Lưu dữ liệu không thành công!' . $e->getMessage(), 'error' => 1)); } } }
public function addProductUser(Request $request) { $token = $request->get('_token'); if ($token != '') { try { // data about truc $productName = date('dmY'); $from = $request->get('from'); $to = $request->get('to'); $product_type = $request->get('product_type'); $unit = $request->get('unit'); $description = $request->get('description'); $address_detail_from = $request->get('address_detail_from'); $phone_number_from = $request->get('phone_number_from'); $email_from = $request->get('email_from'); $email_to = $request->get('email_to'); $address_detail_to = $request->get('address_detail_to'); $phone_number_to = $request->get('phone_number_to'); $created_at = date('Y-m-d H:i:s'); $data = array('product_name' => 'P' . $productName, 'comefrom' => $from, 'cometo' => $to, 'product_type' => $product_type, 'unit' => $unit, 'description' => $description, 'created_at' => $created_at, 'address_detail_to' => $address_detail_to, 'phone_to' => $phone_number_to, 'email_to' => $email_to, 'addresst_detail_from' => $address_detail_from, 'phone_from' => $phone_number_from, 'email_from' => $email_from); $id_product = Product::getInstance()->insert($data); // data for user $id_user = Session::get('user')->id; $input = array('user_id' => $id_user, 'custome_id' => $id_product, 'type' => 'product', 'status' => 'enable', 'created_at' => date('Y-m-d h:i:s')); // $input_price = array( // 'price_sum' => $price_sum, // 'foreign_key' => $id_product // ); // $id_price = Price::getInstance()->insert($input_price); $id_relation = Relation::getInstance()->insert($input); if ($id_relation) { return response()->json(array('message' => 'Lưu dữ liệu thành công!', 'error' => 0)); } else { return response()->json(array('message' => 'Lưu dữ liệu không thành công!', 'error' => 1)); } } catch (\Exception $e) { return response()->json(array('message' => 'Lưu dữ liệu không thành công!' . $e->getMessage(), 'error' => 1)); } } }