本文整理匯總了PHP中app\News::tags方法的典型用法代碼示例。如果您正苦於以下問題:PHP News::tags方法的具體用法?PHP News::tags怎麽用?PHP News::tags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\News
的用法示例。
在下文中一共展示了News::tags方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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();
}