diff --git a/app/Http/Controllers/Bo/PromotionsController.php b/app/Http/Controllers/Bo/PromotionsController.php index 4c35a305..36ca7743 100644 --- a/app/Http/Controllers/Bo/PromotionsController.php +++ b/app/Http/Controllers/Bo/PromotionsController.php @@ -29,7 +29,13 @@ class PromotionsController extends Controller public function create() { $discTypes = DiscountType::all(); - return view('bo.promotions.create', compact('discTypes')); + + $existingProds = Product::all(); + $promotion = new Promotion(); + $selectedProds = $promotion->products; + //$existingProds = $existingProds->diff($selectedProds); + + return view('bo.promotions.create', compact('discTypes', 'existingProds', 'selectedProds')); } /** @@ -40,14 +46,17 @@ class PromotionsController extends Controller */ public function store(Request $request) { + + $request->validate([ + 'product_id' => 'required', + ]); + $productIds = explode(",", $request->product_id); $discType = $request->discount_type_id; $value = $request->discount_value; $date_start = $request->date_start_date . " " . $request->date_start_time; $date_end = $request->date_end_date . " " . $request->date_end_time; - $request->validate([]); - $promotion = new Promotion(); $promotion->discount_type_id = $discType; $promotion->discount_value = $value; @@ -101,14 +110,16 @@ class PromotionsController extends Controller { $promotion = Promotion::findOrFail($id); + $request->validate([ + 'product_id' => 'required', + ]); + $productIds = explode(",", $request->product_id); $discType = $request->discount_type_id; $value = $request->discount_value; $date_start = $request->date_start_date . " " . $request->date_start_time; $date_end = $request->date_end_date . " " . $request->date_end_time; - $request->validate([]); - $promotion->discount_type_id = $discType; $promotion->discount_value = $value; $promotion->date_start = $date_start; diff --git a/public/b-o/js/app.js b/public/b-o/js/app.js index cdfefee4..fcfc4119 100644 --- a/public/b-o/js/app.js +++ b/public/b-o/js/app.js @@ -12438,7 +12438,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len return { selectedProds: [], existingProds: [], - product_id: '' + product_id: '', + dropOptions: { + className: "ghost", + animationDuration: 300, + showOnTop: true + } }; }, mounted: function mounted() { @@ -12453,7 +12458,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len methods: { onDrop: function onDrop(collection, dropResult) { this[collection] = this.applyDrag(this[collection], dropResult); - console.log(this[collection]); this.product_id = this.selectedProds.map(function (_ref2) { var id = _ref2.id; return id; @@ -12465,13 +12469,6 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len getChildPayload2: function getChildPayload2(index) { return this.selectedProds[index]; }, - dropOptions: function dropOptions() { - return { - className: "ghost", - animationDuration: 300, - showOnTop: true - }; - }, applyDrag: function applyDrag(arr, dragResult) { var removedIndex = dragResult.removedIndex, addedIndex = dragResult.addedIndex, diff --git a/resources/js/components/ProductsCardsDnd.vue b/resources/js/components/ProductsCardsDnd.vue index f4988595..b47b47f9 100644 --- a/resources/js/components/ProductsCardsDnd.vue +++ b/resources/js/components/ProductsCardsDnd.vue @@ -55,6 +55,11 @@ export default { selectedProds: [], existingProds: [], product_id: '', + dropOptions: { + className: "ghost", + animationDuration: 300, + showOnTop: true, + }, } }, mounted() { @@ -66,7 +71,6 @@ export default { methods: { onDrop (collection, dropResult) { this[collection] = this.applyDrag(this[collection], dropResult); - console.log(this[collection]); this.product_id = this.selectedProds.map(({ id }) => id ); }, @@ -78,14 +82,6 @@ export default { return this.selectedProds[index] }, - dropOptions() { - return { - className: "ghost", - animationDuration: 300, - showOnTop: true, - } - }, - applyDrag(arr, dragResult) { const { removedIndex, addedIndex, payload } = dragResult if (removedIndex === null && addedIndex === null) return arr diff --git a/resources/views/bo/promotions/create.blade.php b/resources/views/bo/promotions/create.blade.php index 29f1f2cc..7b26103a 100644 --- a/resources/views/bo/promotions/create.blade.php +++ b/resources/views/bo/promotions/create.blade.php @@ -19,11 +19,14 @@ @endif - {{-- //TODO implementer plus tard --}} -
- + + {{----}}