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


PHP Participant::firstOrCreate方法代码示例

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


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

示例1: update

 /**
  * 更新请求
  *
  * @param Request $request
  * @param int $id
  * @return void
  */
 public function update(Request $request, $id)
 {
     // 验证
     $this->validate($request, ['topic' => 'string', 'participants' => 'string', 'state' => 'required|in:1,-1', 'reply_message' => 'required|string']);
     $log = Comment::find($id);
     // 更新
     DB::transaction(function () use($request, $log) {
         if (Comment::STATUS['ENABLE'] == $request->state) {
             // 参与人
             $participantIds = [];
             $participantNames = Participant::filterParticipantNames($request->participants);
             if (!empty($participantNames)) {
                 foreach ($participantNames as $name) {
                     $participant = Participant::firstOrCreate(['name' => $name]);
                     $participant->increment('counts', 1);
                     $participantIds[] = $participant->id;
                 }
             }
             // 节目
             $program = Program::where('date', date('Y-m-d', strtotime($log->metas->thread_key)))->first();
             $topic = Program::filterTopic($request->topic);
             if (!empty($topic)) {
                 $program->update(['topic' => $topic]);
             }
             if (!empty($participantIds)) {
                 $program->participants()->sync($participantIds);
             }
         }
         // 刷新首页文件缓存
         Cache::forget(Program::INDEX_CACHE_KEY);
         // 刷新贡献记录页文件缓存
         Cache::forget(Comment::CONTRIBUTION_CACHE_KEY);
         // 记录日志
         Comment::where('id', $log->id)->update(['ext_is_agree' => $request->state]);
     });
     // 回复评论
     $state = Comment::replyPost($request->reply_message, $log->metas->thread_id, $log->metas->post_id, $log->metas->author_email);
     // 跳转
     $status = ['status' => $state ? 'success' : 'error', 'message' => $state ? '审核成功~' : '审核成功,回复失败'];
     return Redirect::to($request->_redirect_url)->with($status['status'], $status['message']);
 }
开发者ID:popfeng,项目名称:zao,代码行数:48,代码来源:ContributionsController.php

示例2: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // 获取文本路径
     $path = $this->argument('path');
     if (!is_file($path)) {
         return $this->error("Invalid file path {$path}.");
     }
     // 解析数据
     $list = self::decodeText($path);
     // 插入数据
     foreach ($list as $group) {
         DB::transaction(function () use(&$group) {
             // 插入声音记录
             self::insertAudios($group);
             // 插入参与人记录
             $data = $group['all'] ?? end($group);
             $participantIds = [];
             $participantNames = Participant::filterParticipantNames($data['participant']);
             foreach ($participantNames as $name) {
                 $participant = Participant::firstOrCreate(['name' => $name]);
                 $participant->increment('counts', 1);
                 $participantIds[] = $participant->id;
             }
             // 插入节目记录
             $topic = Program::filterTopic($data['topic']);
             if (empty($group['all'])) {
                 if (in_array(mb_substr($topic, -1), ['a', 'b', 'c'])) {
                     $topic = mb_substr($topic, 0, -1);
                 }
             }
             $program = Program::firstOrCreate(['date' => $data['date'], 'topic' => $topic, 'state' => Program::STATE_ENABLE]);
             if (!empty($participantIds)) {
                 $program->participants()->sync($participantIds);
             }
             // 输出日期
             $this->info(sprintf("%s\t%s", $data['date'], $topic));
         });
     }
 }
开发者ID:popfeng,项目名称:zao,代码行数:44,代码来源:Import.php


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