本文整理匯總了PHP中app\Post::whereHas方法的典型用法代碼示例。如果您正苦於以下問題:PHP Post::whereHas方法的具體用法?PHP Post::whereHas怎麽用?PHP Post::whereHas使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Post
的用法示例。
在下文中一共展示了Post::whereHas方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getFavorites
public function getFavorites()
{
$posts = Post::whereHas('favored', function ($q) {
$q->where('post_user.user_id', Auth::user()->id);
})->ordered()->paginate(30);
return view('posts.index', compact('posts'));
}
示例2: searchQuestions
public function searchQuestions($keyword)
{
$posts = Post::whereHas('tags', function ($query) use($keyword) {
$query->where('name', 'LIKE', '%' . $keyword . '%');
})->orWhere('title', 'LIKE', '%' . $keyword . '%')->orWhere('body', 'LIKE', '%' . $keyword . '%')->get();
return $posts;
}
示例3: getReportedPostsViewable
/**
* Fetches all reports that this user can view (not submitted reports).
*
* @return Collection
*/
public function getReportedPostsViewable($onlyDirect = false)
{
return Post::whereHas('reports', function ($query) use($onlyDirect) {
$query->whereOpen();
if ($onlyDirect) {
$query->whereIn('board_uri', $this->canInBoards('board.reports'));
}
})->withEverything()->get();
}
示例4: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$post = Post::whereHas('user', function ($q) {
$q->where('id', $this->user->id);
})->where('id', $id)->get()->first();
if (empty($post)) {
return response()->json(['success' => false, 'errors' => ['Not user']], 200);
}
$post->delete();
return response()->json(['success' => true], 200);
}