本文整理汇总了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!');
}