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


PHP Tag::firstOrCreate方法代码示例

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


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

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @param URI int $fact_id
  * @return Response
  */
 public function store(Request $request, $user_id = null, $fact_id = null)
 {
     if (!$request->input('tag_name')) {
         return $this->respondUnprocessed();
     }
     $fact = Fact::find($fact_id);
     if ($user_id) {
         $authUser = Auth::ID();
         if ($authUser != $user_id) {
             return $this->respondForbidden("Unauthorized: Must be logged to access endpoint");
         }
         if ($fact->user_id != $user_id) {
             return $this->respondForbidden("Unauthorized: Verify you still have access to resource");
         }
     }
     if (!$fact) {
         return $this->respondNotFound("Fact Not found");
     } else {
         $tag_name = $request->input('tag_name');
         $tag = Tag::firstOrCreate(['tag_name' => $tag_name]);
         if ($tag) {
             TaggedFact::create(['fact_id' => $fact_id, 'tag_id' => $tag->id]);
             $metadata = ['tag_id' => $tag->id];
             return $this->respondCreated("Request Successful", $metadata);
         } else {
             return $this->respondUnprocessed("Unable to tag the fact");
         }
     }
 }
开发者ID:RichNwankwo,项目名称:Gladysrepo,代码行数:36,代码来源:TagFactController.php

示例2: tagsIds

 private function tagsIds($_tags)
 {
     $tags = array_filter(array_map('trim', explode(",", $_tags)));
     $tagsIds = [];
     foreach ($tags as $tag) {
         $tagsIds[] = \App\Models\Tag::firstOrCreate(['name' => $tag])->id;
     }
     return $tagsIds;
 }
开发者ID:pauloricardo,项目名称:blog-son-laravel,代码行数:9,代码来源:PostsAdminController.php

示例3: migrate_events

 protected function migrate_events()
 {
     $website = Website::first();
     $data_users = User::get();
     foreach ($data_users as $user) {
         $users[$user['username']] = $user;
     }
     // get old articles
     DB::connection('mongodb')->collection('posts')->where('category', 'regex', '/events/i')->chunk(1000, function ($data) use($new_collection, $users, $website) {
         foreach ($data as $x) {
             unset($tags);
             $tags[] = 'events';
             if (str_is('*car free day*', strtolower($x['title']))) {
                 $tags[] = 'cfd';
             }
             if (str_is('*seminar*', strtolower($x['title']))) {
                 $tags[] = 'seminar';
             }
             if (str_is('*opening*', strtolower($x['title']))) {
                 $tags[] = 'opening';
             }
             if (str_is('*ustad*', strtolower($x['title']))) {
                 $tags[] = 'religius';
             }
             if (str_is('*clothing*', strtolower($x['title']))) {
                 $tags[] = 'pameran';
             }
             if (str_is('*konser*', strtolower($x['title'])) || str_is('*concert*', strtolower($x['title'])) || str_is('*cherry bell*', strtolower($x['title']))) {
                 $tags[] = 'konser';
             }
             if (str_is('*brawijaya*', strtolower($x['title']))) {
                 $tags[] = 'brawijaya';
             }
             if (str_is('*stand up comedy*', strtolower($x['title']))) {
                 $tags[] = 'stand up comedy';
             }
             if (str_is('*job fair*', strtolower($x['title'])) || str_is('*career expo*', strtolower($x['title']))) {
                 $tags[] = 'job fair';
             }
             if (str_is('*film*', strtolower($x['title']))) {
                 $tags[] = 'film';
             }
             if (str_is('*film*', strtolower($x['title']))) {
                 $tags[] = 'film';
             }
             if (str_is('*lomba*', strtolower($x['title'])) || str_is('*kompetisi*', strtolower($x['title']))) {
                 $tags[] = 'kompetisi';
             }
             if ($x['tgl_published']) {
                 $news = new Event(['title' => $x['title'], 'slug' => str_replace('.', '', $x['url']), 'summary' => str_limit(strip_tags(str_replace("\n", "", $x['full'])), 125), 'content' => $x['full'], 'published_at' => date('Y-m-d H:i:s', $x['tgl_published']->sec), 'created_at' => $x['tgl'], 'updated_at' => $x['tgl'], 'user_id' => array_key_exists($x['author'], $users) ? $users[$x['author']]->id : $users['dita']->id, 'started_at' => $x['extra_field']['event_tgl_start']->sec, 'ended_at' => isset($x['extra_field']['event_tgl_end']) ? $x['extra_field']['event_tgl_end']->sec : $x['extra_field']['event_tgl_start']->sec, 'location' => isset($x['extra_field']['event_lokasi']) ? $x['extra_field']['event_lokasi'] : '', 'komunitas_id' => Directory::where('ori_id', '=', $x['extra_field']['event_komunitas'])->first()->id, 'views' => isset($x['views']) ? $x['views'] : 0]);
                 if (!$news->save()) {
                     print_r($news->toArray());
                     dd($news->getErrors());
                 }
                 // ----------------------------------------------------------------------------------------------------
                 // IMAGE
                 // ----------------------------------------------------------------------------------------------------
                 $s_image = new Image(['name' => 'sm', 'path' => $x['thumbmail'], 'title' => '', 'description' => '']);
                 $m_image = new Image(['name' => 'md', 'path' => $x['image'], 'title' => '', 'description' => '']);
                 $l_image = new Image(['name' => 'lg', 'path' => $x['image'], 'title' => '', 'description' => '']);
                 $news->images()->updateOrCreate(['name' => 'sm'], $s_image->toArray());
                 $news->images()->updateOrCreate(['name' => 'md'], $m_image->toArray());
                 $news->images()->updateOrCreate(['name' => 'lg'], $l_image->toArray());
                 // ----------------------------------------------------------------------------------------------------
                 // TAG
                 // ----------------------------------------------------------------------------------------------------
                 unset($tags_model);
                 $tags_model = new Collection();
                 foreach ($tags as $tag) {
                     $tags_model[] = Tag::firstOrCreate(['name' => $tag]);
                 }
                 foreach ($tags_model as $k => $v) {
                     if (!$tags_model[$k]->save()) {
                         dd($tags_model[$k]->getErrors());
                     }
                 }
                 if (count($tags_model)) {
                     $news->tags()->sync($tags_model->lists('id'));
                 }
                 // ----------------------------------------------------------------------------------------------------
                 // WEBSITE
                 // ----------------------------------------------------------------------------------------------------
                 $news->websites()->sync([$website->id]);
                 // ----------------------------------------------------------------------------------------------------
                 // LOG
                 // ----------------------------------------------------------------------------------------------------
                 // $news->authored()->attach(array_key_exists($x['author'], $users) ? $users[$x['author']]->id : $users['dita']->id, ['original_data' => json_encode([]), 'updated_data' => $news->toJson()]);
             }
             // $news->websites()->associate($website);
             // $news->save();
         }
     });
     // save to new tables
 }
开发者ID:ThunderID,项目名称:Halo,代码行数:94,代码来源:newHalo.php

示例4: syncTags

 protected function syncTags(&$confession)
 {
     $tagNames = $this->getTagNamesFromContent($confession->content);
     $tagsToSync = [];
     foreach ($tagNames as $tagName) {
         $tag = Tag::firstOrCreate(['confession_tag' => $tagName]);
         $tagsToSync[] = $tag->confession_tag_id;
     }
     $confession->tags()->sync($tagsToSync);
     return $confession;
 }
开发者ID:nekonekonik,项目名称:nuswhispers,代码行数:11,代码来源:ConfessionsRepository.php


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