コード例 #1
0
 /**
  * Creates an activity
  *
  * @param null|array $data
  * @return null|ActivityModel
  */
 public function create($data = null)
 {
     DB::beginTransaction();
     try {
         if (is_null($data)) {
             throw new NullDataException('The data array is required!');
         }
         foreach ($data as $k => $v) {
             if (!in_array($k, $this->fields)) {
                 throw new CreateActivityException('Please add the correct fields!');
             }
         }
         if (count(array_keys($data)) != count($this->fields)) {
             throw new CreateActivityException('The number of given data is different than required!');
         }
         $this->checkFields($data);
         $activity = ActivityModel::create($data);
         DB::commit();
         return $activity;
     } catch (NullDataException $e) {
         DB::rollBack();
         return $e;
     } catch (CreateActivityException $e) {
         DB::rollBack();
         return $e;
     }
 }
コード例 #2
0
 public function store(CreateActivityRequest $request)
 {
     $activity = ActivityModel::create($request->all());
     return ActivityModel::whereId($activity->id)->with('type')->first()->toJson();
 }