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


PHP Article::firstOrNew方法代码示例

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


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

示例1: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $sources = Source::all();
     foreach ($sources as $source) {
         $feed = Feeds::make($source->feed_url);
         $items = $feed->get_items();
         foreach ($items as $item) {
             $article = Article::firstOrNew(['link' => $item->get_permalink()]);
             $article->source_id = $source->id;
             $article->title = $item->get_title();
             $article->content = $item->get_description();
             if ($item->get_date()) {
                 $article->date = Carbon::createFromFormat('j F Y, g:i a', $item->get_date());
             } else {
                 $article->date = Carbon::now();
             }
             if (!empty($article->content)) {
                 // Disable HTML 5 related errors
                 libxml_use_internal_errors(true);
                 $doc = new DOMDocument();
                 $doc->loadHTML($article->content);
                 $imageTags = $doc->getElementsByTagName('img');
                 foreach ($imageTags as $tag) {
                     $src = $tag->getAttribute('src');
                     if (strpos($src, ".jpg") or strpos($src, ".png") or strpos($src, ".jpeg")) {
                         $article->image_url = $src;
                         break;
                     }
                 }
             }
             $article->save();
         }
     }
 }
开发者ID:NewsRepost,项目名称:Fetcher,代码行数:39,代码来源:FetchSources.php

示例2: postIndex

 /**
  * Обработчик запроса на сохранение данных.
  *
  * @param StoreContactsRequest $request
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postIndex(StoreContactsRequest $request)
 {
     // Сохраняем координаты в таблице настроек
     Memory::put('contacts.latitude', $request->get('latitude'));
     Memory::put('contacts.longitude', $request->get('longitude'));
     // Данные статей
     Model::unguard();
     $contacts_form_text = Article::firstOrNew(['type' => 'contacts_form_text']);
     $contacts_contacts = Article::firstOrNew(['type' => 'contacts_contacts']);
     $contacts_working_time = Article::firstOrNew(['type' => 'contacts_working_time']);
     $contacts_why_us = Article::firstOrNew(['type' => 'contacts_why_us']);
     // Обновляем тексты
     $contacts_form_text->full_text = $request->get('contacts_form_text');
     // настройки СЕО
     $contacts_form_text->page_title = $request->get('page_title');
     $contacts_form_text->page_keywords = $request->get('page_keywords');
     $contacts_form_text->page_description = $request->get('page_description');
     $contacts_form_text->page_h1 = $request->get('page_h1');
     $contacts_contacts->full_text = $request->get('contacts_contacts');
     $contacts_working_time->full_text = $request->get('contacts_working_time');
     $contacts_why_us->full_text = $request->get('contacts_why_us');
     // Сохранение
     $contacts_form_text->save();
     $contacts_contacts->save();
     $contacts_working_time->save();
     $contacts_why_us->save();
     Model::reguard();
     return redirect()->action('Admin\\ContactsController@getIndex')->with('success', 'Данные успешно сохранены.');
 }
开发者ID:alexmon1989,项目名称:kadsgroup,代码行数:35,代码来源:ContactsController.php


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