Example #1
0
 /**
  * Creates a new Point model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Point();
     $model->create_at = time();
     $model->user_id = User::getCurrentId();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, Point::$validation_rules);
     $point = new Point();
     $point->name = $request->input('name');
     $point->description = $request->input('description');
     $point->parent_id = $request->input('parent_id');
     $point->line_id = $request->input('line_id');
     $point->type_id = $request->input('type_id');
     $point->user_id = $request->input('user_id');
     // Check if the chosen point type is available
     if (in_array($point->type_id, \Config::get('sf.unique_type_ids'))) {
         $type_check = Point::where('line_id', $point->line_id)->where('type_id', $point->type_id)->first();
         if (!empty($type_check)) {
             Flash::danger(trans('alerts.point.point_already_set'));
             return redirect()->back()->withInput();
         }
     }
     $point->save();
     Flash::success(trans('alerts.point.added'));
     return redirect(action("StorylineController@show", ['id' => $point->line_id]));
 }