| @@ 18-33 (lines=16) @@ | ||
| 15 | * |
|
| 16 | * @return Response |
|
| 17 | */ |
|
| 18 | public function create() |
|
| 19 | { |
|
| 20 | try { |
|
| 21 | // create our new inventory |
|
| 22 | $data = input('inventory'); |
|
| 23 | unset($data['id']); |
|
| 24 | $inventory = Inventory::create($data); |
|
| 25 | $inventory->load('values'); |
|
| 26 | ||
| 27 | // return the new option |
|
| 28 | return Response::make($inventory, 200); |
|
| 29 | } catch (Exception $e) { |
|
| 30 | // if anything went wrong, send back the error message |
|
| 31 | return Response::make($e->getMessage(), 500); |
|
| 32 | } |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * Validate an inventory. |
|
| @@ 40-52 (lines=13) @@ | ||
| 37 | * |
|
| 38 | * @return Response |
|
| 39 | */ |
|
| 40 | public function validate() |
|
| 41 | { |
|
| 42 | try { |
|
| 43 | $data = input('inventory'); |
|
| 44 | $inventory = Inventory::findOrNew($data['id']); |
|
| 45 | $inventory->fill($data); |
|
| 46 | $inventory->validate(); |
|
| 47 | ||
| 48 | return Response::make($inventory, 200); |
|
| 49 | } catch (Exception $e) { |
|
| 50 | return Response::make($e->getMessage(), 500); |
|
| 51 | } |
|
| 52 | } |
|
| 53 | } |
|
| 54 | ||
| @@ 45-57 (lines=13) @@ | ||
| 42 | * |
|
| 43 | * @return Response |
|
| 44 | */ |
|
| 45 | public function validate() |
|
| 46 | { |
|
| 47 | try { |
|
| 48 | $data = input('option'); |
|
| 49 | $option = Option::with('values')->findOrNew($data['id']); |
|
| 50 | $option->fill($data); |
|
| 51 | $option->validate(); |
|
| 52 | ||
| 53 | return Response::make($option, 200); |
|
| 54 | } catch (Exception $e) { |
|
| 55 | return Response::make($e->getMessage(), 500); |
|
| 56 | } |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||