/** * Insert a new entry * @param Request $request */ public function store(Request $request) { $entry = new Entry($request->except(['restoration_type_id', 'folders'])); $restorationType = RestorationType::find($request->get('restoration_type_id')); $entry->restorationType()->associate($restorationType); $entry->save(); //Attach the folders foreach ($request->get('folders') as $folder_id) { $entry->folders()->attach($folder_id); } }
/** * Creates a new Entry model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id) { $model = new Entry(); // Check if Contest ID Passed if ($id === null) { throw new \yii\web\HttpException(404, Yii::t('alerts', 'The requested Item could not be found.')); } $model->contest_id = $id; if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['contest/view', 'id' => $model->contest_id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreateentry() { $name = Yii::$app->request->post('name'); $body = Yii::$app->request->post('body'); $category = Yii::$app->request->post('category'); Yii::$app->response->format = Response::FORMAT_JSON; $entry = new Entry(); $entry->name = $name; $entry->body = Markdown::convert($body); $entry->category = $category; $entry->save(); $tag = EntryTag::setTags($entry->id, Yii::$app->request->post('tags')); return $tag; }
public function run() { $this->faker = Faker::create(); Entry::truncate(); DB::table('entry_folder')->truncate(); foreach (range(0, 20) as $index) { $originalRestorationDate = $this->faker->dateTimeBetween('-10 years', '-2 years')->format('Y-m-d'); $lastPhotoDate = $this->faker->dateTimeBetween('-2 years', 'now')->format('Y-m-d'); $restorationAge = Carbon::createFromFormat('Y-m-d', $lastPhotoDate)->diffInMonths(Carbon::createFromFormat('Y-m-d', $originalRestorationDate)) / 12; $restorationAge = round($restorationAge * 2) / 2; $entry = new Entry(['first_name' => $this->faker->firstName, 'last_name' => $this->faker->lastName, 'tooth_number' => $this->faker->numberBetween(1, 6), 'original_restoration_date' => $originalRestorationDate, 'last_photo_date' => $lastPhotoDate, 'restoration_age' => $restorationAge, 'note' => $this->faker->sentence()]); $restorationTypeIds = RestorationType::lists('id')->all(); $restorationTypeId = $this->faker->randomElement($restorationTypeIds); $restorationType = RestorationType::find($restorationTypeId); $entry->restorationType()->associate($restorationType); $entry->save(); $folderCount = $this->faker->numberBetween(1, 2); $folder_ids = $this->faker->randomElements(Folder::lists('id')->all(), $folderCount); foreach ($folder_ids as $folder_id) { $entry->folders()->attach($folder_id); } } }