Пример #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     // Item object
     $item = new Item();
     $item = $this->getRequestItem($request, $item);
     $item->comment = '';
     //// category object
     $category = new Category();
     $category->name = $request->get('category');
     $category->container_id = $request->get('container_id');
     //// save
     try {
         $item = Item::persist($item, $category)->toArray();
         $item['category'] = $category->name;
         return $item;
     } catch (\PDOException $e) {
         //// duplicate item
         if (Utils::isDbIntegrityException($e)) {
             $errorMessage = 'Item "' . $item->name . '" already exists in category "' . $category->name . '".';
             Log::info($e->getMessage());
             return response()->json(['error' => $errorMessage], 400);
         } else {
             throw $e;
         }
     }
 }
Пример #2
0
 protected function changelog($model, $changes)
 {
     $this->user_id = $this->user;
     $log = new Changelog();
     $log->user_id = $this->user;
     $log->before = json_encode($model);
     $log->after = json_encode($changes);
     $log->table = $this->getTable();
     try {
         $log->save();
     } catch (\PdoException $e) {
         //// hack for multiple calls for same event
         if (Utils::isDbIntegrityException($e)) {
             Log::error('ChangelogModelBase: Multiple calls for same event. ' . json_encode($log));
         } else {
             throw $e;
         }
     }
 }