本文整理汇总了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();
}
}
}
示例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', 'Данные успешно сохранены.');
}