public function postDiscount() { $id = \Input::get('id'); $rules = array('pricelist_id' => 'required', 'code' => 'required', 'expiry_date' => 'required', 'percent' => 'required|numeric|min:1|max:100'); $validation = \Validator::make(\Input::all(), $rules); if ($validation->passes()) { $pricelist_id = \Input::get('pricelist_id'); $code = \Input::get('code'); $expiry_date = \Input::get('expiry_date'); $percent = \Input::get('percent'); $pricelist = Pricelist::find($pricelist_id); // No such id if ($pricelist == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "The pricelist for discount may have been deleted. Please try again."); return \Redirect::to('admin/pricelists')->withErrors($errors)->withInput(); } $newDiscount = new Discount(); $newDiscount->code = $code; $newDiscount->expiry_date = date_create_from_format('d/m/Y H:i:s', $expiry_date . ' 00:00:00'); $newDiscount->percent = $percent; $pricelist->discounts()->save($newDiscount); } else { return \Redirect::to('admin/pricelists')->withErrors($validation)->withInput(); } return \Redirect::to('admin/pricelists'); }
<?php include_once 'pricelist_class.php'; ?> <?php if ($_POST['AddSubmit']) { $pricelist = new Pricelist(); $pricelist->pricelistAdd(); } ?> <!DOCTYPE html> <html lang="ru"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags --> <meta name="description" content=""> <meta name="author" content=""> <link rel="icon" href="../../favicon.ico"> <title>тест: добавляем группу</title> <!-- Bootstrap core CSS --> <link href="css/bootstrap.min.css" rel="stylesheet"> <!-- Custom styles for this template --> <link href="signin.css" rel="stylesheet"> <!-- Just for debugging purposes. Don't actually copy these 2 lines! --> <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
public function getDelete($id) { // Find the module using the user id $module = Module::find($id); if ($module == null) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "We are having problem deleting this entry. Please try again."); return \Redirect::to('admin/modules')->withErrors($errors); } $purchases = UserPricelist::join('pricelists', 'pricelists.id', '=', 'user_pricelists.pricelist_id')->where('pricelists.module_id', $id)->get(); if (count($purchases) > 0) { $errors = new \Illuminate\Support\MessageBag(); $errors->add('deleteError', "This module has been purchased before. You cannot delete it. Please change disable it instead."); return \Redirect::to('admin/modules')->withErrors($errors); } // Delete all images first $module->deleteAllImages(); // Delete all tags $module->deleteAllTags(); // Delete all pricelist foreach (Pricelist::where('module_id', $id)->get() as $pricelist) { $pricelist->delete(); } // Delete all media links foreach (ModuleMediaMembership::where('module_id', $id)->get() as $mmm) { $mmm->delete(); } // Delete the module $module->delete(); return \Redirect::to('admin/modules'); }