本文整理汇总了PHP中app\models\News::findOrNew方法的典型用法代码示例。如果您正苦于以下问题:PHP News::findOrNew方法的具体用法?PHP News::findOrNew怎么用?PHP News::findOrNew使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\News
的用法示例。
在下文中一共展示了News::findOrNew方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
/**
* @param $id
* @return mixed
* @throws GeneralException
*/
public function find($id)
{
$obj = News::findOrNew($id);
if (!is_null($obj)) {
return $obj;
}
return array();
}
示例2: fieldsFromModel
/**
* Return the field values from the model
*
* @param integer $id
* @param array $fields
* @return array
*/
protected function fieldsFromModel($id, array $fields)
{
$news = News::findOrNew($id);
$fieldNames = array_keys(array_except($fields, ['tags']));
$fields = ['id' => $id];
foreach ($fieldNames as $field) {
$fields[$field] = $news->{$field};
}
$fields['tags'] = $news->tags()->lists('tag')->all();
return $fields;
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param NewsUpdateRequest $request
* @param int $id
* @return Response
*/
public function update(NewsUpdateRequest $request, $id)
{
$news = News::findOrNew($id);
if ($this->repository->update($id, $request->newsFillData())) {
Log::info('update...' . Input::get('tags'));
$tags = Input::get('tags') ? array_map('trim', explode(',', Input::get('tags'))) : [];
$news->syncTags($tags);
return Redirect::to('admin/news');
} else {
//return Redirect::back()->withInput()->withErrors('保存失败!');
}
}
示例4: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$newsModel = News::findOrNew($id);
$newsFields = $this->doValidation($request, News::getValidatorRules());
$newsFields["Story_Date"] = Carbon::parse($newsFields["Story_Date"]);
$newsFields['Date_Modified'] = Carbon::now();
$newsModel->fill($newsFields)->save();
$this->saveObjectRelation($request, $newsModel);
return redirect(route('admin.news.index'))->with('flash', 'The News was updated');
}