本文整理匯總了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');
}