本文整理汇总了PHP中app\Comment::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Comment::with方法的具体用法?PHP Comment::with怎么用?PHP Comment::with使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Comment
的用法示例。
在下文中一共展示了Comment::with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: comments
/**
* Display all comments by User
*
* @return Response
*/
public function comments($userId)
{
if (!User::find($userId)) {
throw new NotFoundHttpException('no user found');
}
$comments = Comment::with('post', 'post.post_author')->where('user_id', $userId)->get();
return response()->json($comments);
}
示例2: storeComment
public function storeComment($itemId, Request $request)
{
$item = Item::with('comments.user')->findOrFail($itemId);
$comment = new Comment(['user_id' => $request->userId, 'message' => $request->message]);
$newComment = $item->comments()->save($comment);
$result = Comment::with('user')->findOrFail($newComment->id);
event(new UserPostedAComment($result));
return $result;
}
示例3: management
public function management()
{
if (Auth::user()) {
$comments = Comment::with('product')->get();
$data['header'] = 'comment management';
return view('comment.management', compact('comments'), $data);
} else {
return redirect('/')->with('message', 'you must login to open this page');
}
}
示例4: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$comment = Comment::with('announcement')->find($request->id);
if ($comment->user_id != Auth::user()->id && Auth::user()->level->level < 4) {
Flash::error("Vous ne disposez pas des droits suffisants pour effectuer ceci !");
return Redirect::back();
}
$content = $request->content;
$comment->update(['content' => $content]);
Flash::success('Votre commentaire a bien été modifié !');
return redirect('announcements/view/' . $comment->announcement->slug);
}
示例5: allComments
/**
* Helper method for sorting all the child comments to their parent
*
* @return the sorted comments
**/
private function allComments($post_id)
{
$comments = Comment::with('user')->where('post_id', $post_id)->get();
$comments_by_id = new Collection();
foreach ($comments as $comment) {
$comments_by_id->put($comment->id, $comment);
}
foreach ($comments as $key => $comment) {
$comments_by_id->get($comment->id)->children = new Collection();
if ($comment->parent_id != 0) {
$comments_by_id->get($comment->parent_id)->children->push($comment);
unset($comments[$key]);
}
}
return $comments;
}
示例6: destroy
/**
* Remove the specified resource from storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(Request $request, $id)
{
$comment = Comment::with('replies')->find($id);
// Do not recursively destroy children comments.
// Because 1. Soft delete feature was adopted,
// and 2. it's not just pleasant for authors of children comments to being deleted by the parent author.
if ($comment->replies->count() > 0) {
$comment->delete();
} else {
$comment->forceDelete();
}
// $this->recursiveDestroy($comment);
event(new ModelChanged('comments'));
if ($request->ajax()) {
return response()->json('', 204);
}
flash()->success(trans('forum.deleted'));
return back();
}
示例7: index
/**
* Display a listing of the motion's comments, this code could almost certainly be done better
*
* @return Response
*/
public function index($motion)
{
$comments = array();
if (Auth::user()->can('view-comments')) {
//A full admin who can see whatever
$comments['agreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->agree()->get()->sortByDesc('commentRank')->toArray();
$comments['disagreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->disagree()->get()->sortByDesc('commentRank')->toArray();
} else {
//Load the standard cached comments for the page
$comments = Cache::remember('motion' . $motion->id . '_comments', Setting::get('comments.cachetime', 60), function () use($motion) {
$comments['agreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->agree()->get()->sortByDesc('commentRank')->toArray();
$comments['disagreeComments'] = Comment::with('vote.user', 'commentVotes')->where('motion_id', $motion->id)->disagree()->get()->sortByDesc('commentRank')->toArray();
return $comments;
});
}
$comments['thisUsersComment'] = Comment::where('motion_id', $motion->id)->with('vote')->where('user_id', Auth::user()->id)->first();
$comments['thisUsersCommentVotes'] = CommentVote::where('motion_id', $motion->id)->where('user_id', Auth::user()->id)->get();
return $comments;
}
示例8: index
/**
* Display a listing of comments, be sure to hide the user_id or identifying features if this person is not logged in
*
* @return Response
*/
public function index()
{
$input = Request::all();
if (!isset($input['start_date'])) {
$input['start_date'] = Carbon::today();
}
if (!isset($input['end_date'])) {
$input['end_date'] = Carbon::tomorrow();
}
if (!isset($input['number'])) {
$input['number'] = 1;
}
$validator = Validator::make($input, ['start_date' => 'date', 'end_date' => 'date', 'number' => 'integer']);
if ($validator->fails()) {
return $validator->errors();
}
$comments = Comment::with('commentvotes', 'vote')->betweenDates($input['start_date'], $input['end_date'])->get()->sortBy(function ($comment) {
return $comment->commentvotes->count();
});
return $comments->sortBy('commentRank')->chunk($input['number'])->reverse();
}
示例9: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$comment = Comment::findOrFail($id);
$this->validate($request, ['comment' => 'required|max:255']);
$data = $request->only('comment');
$comment->update($data);
$artikel = Artikel::findOrFail($request->artikel_id);
$comments = Comment::with('user')->where('artikel_id', '=', $id)->get();
Session::put('notiftype', 'success');
Session::put('notifmessage', 'comment edited succesfully.');
return back();
}
示例10: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($community, $id)
{
$post = Post::with('author', 'comments.author', 'community')->where('id', $id)->get();
$comments = Comment::with('author')->where('post_id', $id)->get();
$community = Community::where("id", $community)->get();
$city = City::where('id', $post[0]->city_id)->get();
return view('posts.show', ['post' => $post, "comments" => $comments, 'community' => $community, 'city' => $city]);
}
示例11: renderComments
public function renderComments($id, $video_id)
{
$id = $video_id;
$comments = Comment::with('user', 'video', 'Replay')->where('video_id', $id)->orderBy('created_at', 'desc')->get();
return view('comments.comments', compact('id'))->with('comments', $comments)->render();
}
示例12: findByField
public function findByField($fieldName, $fieldValue, $columns = ['*'])
{
return Comment::with('user')->where($fieldName, $fieldValue)->orderBy('created_at', 'ASC')->get($columns);
}
示例13: comments
public function comments($id)
{
$comments = Comment::with('Author')->where('request_id', $id)->orderBy('created_at', 'desc')->get();
$output = '';
foreach ($comments as $comment) {
$output .= '
<div class="media">
<div class="media-body">
<h4 class="media-heading">' . $comment->comment . '</h4>
' . $comment->author->name . ' @ ' . $comment->created_at . '
</div>
</div>
';
}
return $output;
}
示例14: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
return \App\Comment::with(['post', 'user', 'parentComment', 'childComment'])->find($id);
}
示例15: comments
public function comments()
{
$comments = Comment::with('article')->with('user')->orderBy('created_at', 'DESC')->paginate(10);
return view('admin.articles.comments', compact('comments'));
}