/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $topics = c2a(Topic::lists('id')); $users = c2a(User::lists('id')); foreach (range(1, 100) as $index) { Reply::create(['topic_id' => $faker->randomElement($topics), 'user_id' => $faker->randomElement($users), 'content' => $faker->sentence(100)]); } }
/** * Bootstrap the application services. */ public function boot() { User::observe('App\\Observers\\UserObserver'); Reply::observe('App\\Observers\\ReplyObserver'); Event::observe('App\\Observers\\EventObserver'); Material::observe('App\\Observers\\MaterialObserver'); Account::observe('App\\Observers\\AccountObserver'); FanGroup::observe('App\\Observers\\FanGroupObserver'); Fan::observe('App\\Observers\\FanObserver'); }
public function search($params) { $query = Reply::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $this->addCondition($query, 'id'); $this->addCondition($query, 'topic_id'); $this->addCondition($query, 'content', true); $this->addCondition($query, 'source', true); $this->addCondition($query, 'user_id'); $this->addCondition($query, 'created_at'); $this->addCondition($query, 'updated_at'); return $dataProvider; }
/** * Finds the Reply model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Reply the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Reply::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 保存. * * @param App\Models\Reply $reply reply * @param array $input input * * @return Reply 返回模型 */ public function savePost($reply, $input) { $reply->fill($input); $reply->save(); return $reply; }