当前位置: 首页>>代码示例>>PHP>>正文


PHP Quote::user方法代码示例

本文整理汇总了PHP中Quote::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Quote::user方法的具体用法?PHP Quote::user怎么用?PHP Quote::user使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Quote的用法示例。


在下文中一共展示了Quote::user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: fire

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->line('Lets start our migration.');
     //Migrate Groups to Roles
     $groups = DB::connection('oldmysql')->table('groups');
     $this->line($groups->count() . ' groups[\'s] were found in the legacy database');
     foreach ($groups->get() as $group) {
         $role = new Role();
         $role->name = $group->group;
         $role->save();
     }
     //Migrate Users
     $users = DB::connection('oldmysql')->table('users');
     $this->line($users->count() . ' user[\'s] were found in the legacy database');
     foreach ($users->get() as $user) {
         $this->line('Migrating user: ' . $user->username);
         $newuser = new User();
         $newuser->id = $user->id;
         $newuser->username = $user->username;
         $newuser->email = $user->email;
         $newuser->save();
         //Migrate there group to a role
         $group = DB::connection('oldmysql')->table('groups')->where('id', $user->group)->first();
         $myrole = Role::where('name', $group->group)->first();
         $newuser->roles()->attach($myrole);
         $this->line('Adding user to role: ' . $group->group);
     }
     //Migrate Users
     $quotes = DB::connection('oldmysql')->table('quotes');
     $this->line($quotes->count() . ' quote[\'s] were found in the legacy database');
     foreach ($quotes->get() as $quote) {
         $this->line('Migrating quote: #' . $quote->id);
         $newquote = new Quote();
         $newquote->timestamps = false;
         $newquote->id = $quote->id;
         $newquote->title = $quote->title;
         $newquote->quote = $quote->quote;
         $user = User::find($quote->userid);
         $newquote->user()->associate($user);
         $newquote->status = $quote->approved;
         $newquote->created_at = date('Y-m-d H:i:s', $quote->timestamp);
         $newquote->updated_at = date('Y-m-d H:i:s', $quote->timestamp);
         $newquote->save();
     }
     $votes = DB::connection('oldmysql')->table('votes');
     $this->line($votes->count() . ' vote[\'s] were found in the legacy database');
     foreach ($votes->get() as $vote) {
         $user = User::find($vote->userid);
         $quote = Quote::find($vote->quoteid);
         if ($user && $quote) {
             if ($vote->vote == 1) {
                 $this->line($user->username . ' voted up #' . $quote->id);
             } else {
                 $this->line($user->username . ' voted down #' . $quote->id);
             }
             if ($quote) {
                 $vuser = $quote->voted()->whereUserId($vote->userid)->first();
                 if (!$vuser) {
                     $quote->voted()->attach($user, array('vote' => $vote->vote));
                 } else {
                     $vuser->pivot->vote = $vote->vote;
                     $vuser->pivot->save();
                 }
             }
             //Our confidence has changed in this quote.
             $quote->updateVoteConfidence();
         } else {
             if (!$quote) {
                 $this->line('Vote #' . $vote->id . ' could not be imported because the quote doesn\'t exist');
             }
             if (!$user) {
                 $this->line('Vote #' . $vote->id . ' could not be imported because the user doesn\'t exist');
             }
         }
     }
 }
开发者ID:shiftosnext,项目名称:Quotinator,代码行数:81,代码来源:QuotinatorMigrateCommand.php


注:本文中的Quote::user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。