/** * Store a newly created shop in storage. * * @return Response */ public function store() { $shopValidator = Validator::make($data = Input::all(), Shop::$rules); if ($shopValidator->fails()) { return Redirect::back()->withErrors($shopValidator)->withInput(); } /* Shop */ if (Input::has('createShop')) { Shop::create($data); } $message = "登録しました。"; if (Input::has('deleteShop')) { $s = Shop::where('Tenpo', Input::get('Tenpo'))->first(); Shop::destroy($s->id); $message = "削除しました。"; if (Input::has('selectedShop')) { Input::replace(array('selectedShop', '')); } } if (Input::has('updateShop')) { $messages = array('required' => '新しい店舗名を入力してください。'); $shopValidator = Validator::make($data = Input::all(), Shop::$update_rules, $messages); if ($shopValidator->fails()) { return Redirect::back()->withErrors($shopValidator)->withInput(); } $s = Shop::where('Tenpo', Input::get('Tenpo'))->first(); Shop::destroy($s->id); $data['Tenpo'] = $data['new_shopName']; Shop::create($data); $message = "更新しました。"; } return Redirect::route('employees.index')->with('message', $message); }
if(isset($_POST['submit'])) { $shop = new Shop(); foreach($_POST AS $key => $value) { if(in_array($key, $allowed)) { $$key = $value; if(in_array($key, $required) && $value == '') { $errors[] = "The field <strong>{$key}</strong> is required."; } } } if(count($errors) < 1) { if($shop->create($world, $name, $owner, $managers, $creator, $position1, $position2, $money, $stock)) { $success = "Created shop {$name}, <a href='editor.php?edit={$name}'>edit</a> or <a href='add-item.php?name={$name}'>add items</a>?"; } else { $errors[] = "Could not create shop {$name}!"; } } } if(count($errors) > 0): echo '<p><strong>There was an error processing the form.</strong></p>'; echo '<ul>'; foreach($errors as $error): echo "<li>$error</li>"; endforeach;
public function new_shop() { $rules = array('shop_name' => 'required'); $validator = Validator::make(Input::all(), $rules); if (!$validator->fails()) { $user = Shop::create(Input::only('shop_name')); $user->save(); return Redirect::to('admin/shops')->with('success', 'Shop created successfully!'); } else { return Redirect::back()->withErrors($validator); } }