Ejemplo n.º 1
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     // Seed normal topics
     $topics = factory(PHPHub\Topic::class)->times(100)->make();
     $user_ids = User::lists('id')->toArray();
     $node_ids = Node::lists('id')->toArray();
     foreach ($topics as $topic) {
         $topic->user_id = array_rand($user_ids, 1);
         $topic->node_id = array_rand($node_ids, 1);
         $this->dispatch(new SaveTopic($topic));
     }
     // Seed excellent topics
     $topics = factory(PHPHub\Topic::class)->times(20)->make();
     foreach ($topics as $topic) {
         $topic->user_id = array_rand($user_ids, 1);
         $topic->node_id = array_rand($node_ids, 1);
         $topic->is_excellent = true;
         $this->dispatch(new SaveTopic($topic));
     }
     // Seed wiki topics
     $topics = factory(PHPHub\Topic::class)->times(20)->make();
     foreach ($topics as $topic) {
         $topic->user_id = array_rand($user_ids, 1);
         $topic->node_id = array_rand($node_ids, 1);
         $topic->is_wiki = true;
         $this->dispatch(new SaveTopic($topic));
     }
 }
Ejemplo n.º 2
0
 public function verify($github_name, $login_token)
 {
     $user = User::query()->where(['github_name' => $github_name])->first(['id', 'login_token']);
     if ($user->login_token == $login_token) {
         return $user->id;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     $replies = factory(PHPHub\Reply::class)->times(1000)->make();
     $user_ids = User::lists('id')->toArray();
     $topic_ids = Topic::lists('id')->toArray();
     foreach ($replies as $reply) {
         $reply->user_id = array_rand($user_ids, 1);
         $reply->topic_id = array_rand($topic_ids, 1);
         $reply->save();
     }
 }
Ejemplo n.º 4
0
 public function boot()
 {
     $this->app[DingoAuth::class]->extend('oauth', function ($app) {
         $provider = new OAuth2($app['oauth2-server.authorizer']->getChecker());
         $provider->setUserResolver(function ($id) {
             Auth::loginUsingId($id);
             return User::findOrFail($id);
         });
         $provider->setClientResolver(function ($id) {
             //TODO: Logic to return a client by their ID.
         });
         return $provider;
     });
 }
Ejemplo n.º 5
0
 /**
  * Run the database seeds.
  */
 public function run()
 {
     // Seed normal topics
     $normal_topics = factory(PHPHub\Topic::class)->times(100)->make();
     $wiki_topics = factory(PHPHub\Topic::class, 'wiki')->times(20)->make();
     $excellent_topics = factory(PHPHub\Topic::class, 'excellent')->times(20)->make();
     $topics = array_merge($normal_topics->all(), $wiki_topics->all(), $excellent_topics->all());
     $user_ids = User::lists('id')->toArray();
     $node_ids = Node::lists('id')->toArray();
     foreach ($topics as $topic) {
         $topic->user_id = array_rand($user_ids, 1);
         $topic->node_id = array_rand($node_ids, 1);
         $this->dispatch(new SaveTopic($topic));
     }
 }
Ejemplo n.º 6
0
 /**
  * 增加用户的未读消息数.
  *
  * @param $user_id
  * @param $amount
  */
 public function incrementUnreadMessagesCount($user_id, $amount)
 {
     User::whereId($user_id)->increment(['notification_count' => $amount]);
 }
 /**
  * 生成一条新的 Notification.
  *
  * @param $attributes
  *
  * @return Notification
  */
 public function store($attributes)
 {
     $notification = parent::create($attributes);
     User::whereId($notification->user_id)->increment('notification_count');
     return $notification;
 }
Ejemplo n.º 8
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param array $data
  *
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }