本文整理匯總了PHP中app\Post::whereId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::whereId方法的具體用法?PHP Post::whereId怎麽用?PHP Post::whereId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Post
的用法示例。
在下文中一共展示了Post::whereId方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//edita un post existente
$post = Post::whereId($id)->firstOrFail();
$categories = Category::all();
$selectedCategories = $post->categories->lists('id')->toArray();
return view('backend.posts.edit', compact('post', 'categories', 'selectedCategories'));
}
示例2: showPost
/**
* 顯示具體文章頁麵,閱讀次數加1
*
* @param int $id 文章id
*/
public function showPost($id)
{
$post = Post::whereId($id)->where('is_draft', '==', 0)->firstOrFail();
$post->content = EndaEditor::MarkDecode($post->content);
$read = Post::whereId($id)->first()->read;
$time = Post::whereId($id)->first()->updated_at;
$read++;
Post::whereId($id)->update(['read' => $read, 'updated_at' => $time]);
return view('blog.post')->withPost($post);
}
示例3: update
public function update($id, PostFormRequest $request)
{
$post = Post::whereId($id)->firstOrFail();
$post->title = $request->get('title');
$post->content = $request->get('content');
$post->slug = Str::slug($request->get('title'), '-');
$post->save();
$post->categories()->sync($request->get('categories'));
return redirect(action('Admin\\PostsController@edit', $post->id))->with('status', 'The post has been updated!');
}