本文整理汇总了PHP中app\News::update方法的典型用法代码示例。如果您正苦于以下问题:PHP News::update方法的具体用法?PHP News::update怎么用?PHP News::update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\News
的用法示例。
在下文中一共展示了News::update方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(News $new, Request $request)
{
$new->update($request->except('image'));
if ($request->hasFile('image')) {
$file = $request->file('image');
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$image = Carbon::now() . ' - ' . $filename . '.' . $extension;
$destinationPath = public_path('/uploads/images/');
$request->file('image')->move($destinationPath, $image);
$new->image = $image;
$new->update();
}
flash()->info('Berita telah diperbarui!');
return redirect('/dashboard/news');
}
示例2: update
public function update(News $news, Request $request)
{
//dd($request->all());
$user = $this->user;
$this->validate($request, ['title' => 'required', 'content' => 'required', 'status' => 'required | in:0,1']);
if ($request->hasFile('image')) {
$this->validate($request, ['image' => 'mimes:jpeg,jpg,png,bmp,gif | max:1024']);
$imageName = $this->uploadImage($request->file('image'));
// delete the last image if exist
$path = public_path('images/news/') . '/' . $news->image;
if (File::exists($path)) {
File::delete($path);
}
} else {
$imageName = $news->image;
//old image name
}
$news->update(['title' => $request->input('title'), 'content' => $request->input('content'), 'status' => $request->input('status'), 'user_id' => $user->id, 'image' => $imageName]);
/*
* Register Update Tags
*/
$selected = $this->registerTags($request);
//آی دی های تگ های جدید
$news->tags()->sync($selected);
//sync -> insert new tag and remove old tags
Flash::success(trans('messages.newsEdited'));
return redirect()->back();
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param \App\Http\Requests\NewsRequest $request
* @param \App\News $news
* @return \Illuminate\Http\Response
*/
public function update(Requests\NewsRequest $request, News $news)
{
DB::transaction(function () use($request, $news) {
$update = ['active' => $request->get('active'), 'sort' => $request->get('sort')];
if ($this->systemAdmin) {
$update['department_id'] = $request->get('department_id');
}
$news->update($update);
foreach ($news->langs as $lang) {
$lang->update(['title' => $request->get('title_' . systemTrans($lang['lang_id'])), 'description' => $request->get('description_' . systemTrans($lang['lang_id']))]);
}
});
return redirect(action('Admin\\NewsController@index'))->with('success', 'updated');
}