action = $action; $this->request = $request; $this->model = $coupon; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(Coupon $coupon, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $coupon = $coupon->create($attributes); return $coupon; } public function update(Coupon $coupon, array $request) { $attributes = $request; $coupon->update($attributes); return $coupon; } public function destroy(Coupon $coupon, array $request) { $coupon->delete(); return $coupon; } public function copy(Coupon $coupon, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $coupon = $coupon->replicate(); $coupon->created_at = Carbon::now(); $coupon->save(); return $coupon; } for ($i = 1; $i <= $count; $i++) { $new = $coupon->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $coupon; } }