本文整理汇总了PHP中Post::comments方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::comments方法的具体用法?PHP Post::comments怎么用?PHP Post::comments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Post
的用法示例。
在下文中一共展示了Post::comments方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getIndex
/**
* Returns all the blog posts.
*
* @return View
*/
public function getIndex()
{
// Get all the blog posts
$posts = $this->post->orderBy('created_at', 'DESC')->paginate(10);
$comments = $this->post->comments();
// Show the page
return View::make('site/blog/index', compact('posts'), compact('comments'));
}
示例2: run
public function run()
{
$content = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Praesent vel ligula scelerisque, vehicula dui eu, fermentum velit.
Phasellus ac ornare eros, quis malesuada augue. Nunc ac nibh at mauris dapibus fermentum.
In in aliquet nisi, ut scelerisque arcu. Integer tempor, nunc ac lacinia cursus,
mauris justo volutpat elit,
eget accumsan nulla nisi ut nisi. Etiam non convallis ligula. Nulla urna augue,
dignissim ac semper in, ornare ac mauris. Duis nec felis mauris.';
for ($i = 1; $i <= 20; $i++) {
$post = new Post();
$post->title = "Post no {$i}";
$post->read_more = substr($content, 0, 120);
$post->content = $content;
$post->save();
$maxComments = mt_rand(3, 15);
for ($j = 1; $j <= $maxComments; $j++) {
$comment = new Comment();
$comment->commenter = 'xyz';
$comment->comment = substr($content, 0, 120);
$comment->email = 'xyz@xmail.com';
$comment->approved = 1;
$post->comments()->save($comment);
$post->increment('comment_count');
}
}
}
示例3: displayPost
public function displayPost(Post $post)
{
$previousPost = Post::where('draft', '=', 0)->where('id', '<', $post->id)->max('id');
$nextPost = Post::where('draft', '=', 0)->where('id', '>', $post->id)->min('id');
if (!is_null($previousPost)) {
$previousPostTitle = Post::find($previousPost)->title;
}
if (!is_null($nextPost)) {
$nextPostTitle = Post::find($nextPost)->title;
}
$comments = $post->comments()->where('approved', '=', 1)->get();
$this->layout->title = $post->title;
$this->layout->main = View::make('home')->nest('content', 'posts.show', compact('post', 'comments', 'previousPost', 'nextPost', 'nextPostTitle', 'previousPostTitle'));
}
示例4: newComment
public function newComment(Post $post)
{
$comment = ['commenter' => Input::get('commenter'), 'email' => Input::get('email'), 'comment' => Input::get('comment')];
$rules = ['commenter' => 'required', 'email' => 'required | email', 'comment' => 'required'];
$valid = Validator::make($comment, $rules);
if ($valid->passes()) {
$comment = new Comment($comment);
$comment->approved = 'no';
$post->comments()->save($comment);
/* redirect back to the form portion of the page */
return Redirect::to(URL::previous() . '#reply')->with('success', 'Comment has been submitted and waiting for approval!');
} else {
return Redirect::to(URL::previous() . '#reply')->withErrors($valid)->withInput();
}
}
示例5: showPost
public function showPost(Post $post)
{
$comments = $post->comments()->where('approved', '=', 1)->get();
$this->layout->title = $post->title;
$this->layout->main = View::make('home')->nest('content', 'posts.single', compact('post', 'comments'));
}
示例6: array
$xid = $_GET['xid'];
$url = $_GET['url'];
} else {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$xid = $_POST['xid'];
$url = $_POST['url'];
$fb_prefix = $_POST['fb_prefix'];
}
}
$params = array();
$params['xid'] = $xid;
$params['permalink'] = $url;
if (array_key_exists('fb_prefix', $_GET)) {
}
$entry = new Post($_GET);
$comments = $entry->comments();
?>
</head>
<body>
<h2>TypePad Comment Listing.</h2>
<?php
foreach ($comments as $comment) {
echo ' <div class="comment-outer">
<div class="comment-avatar">
<a href="' . $comment->author->profile_url . '"><img class="avatar" src="' . $comment->author->avatar . '" /></a>
</div>
<div class="comment-contents">
<a href="' . $comment->author->profile_url . '">' . $comment->author->display_name . '</a>
示例7: newCommentReg
public function newCommentReg(Post $post)
{
$inputs = ['user_id' => Input::get('uid'), 'comment' => Input::get('comment'), 'image' => Input::file('image'), 'name' => Input::get('tag')];
$attributeNames = ['name' => 'Tag name'];
$valid = Validator::make($inputs, Comment::$rulesReg);
$valid->setAttributeNames($attributeNames);
$valid->sometimes('name', 'unique:tags|min:3|max:12', function ($inputs) {
return !is_numeric($inputs['name']);
});
if ($valid->passes()) {
$comment = new Comment();
//uncomment the string below to use comment checking by administrator
//$comment->approved = 0;//'no';
$comment->commenter = '';
$comment->email = '';
$comment->user_id = $inputs['user_id'];
$comment->comment = $inputs['comment'];
$tag = $inputs['name'];
$image = $inputs['image'];
if (isset($image)) {
list($width, $height) = getimagesize($image);
$ratio = $height / $width;
$filename = date('Y-m-d-H:i:s') . "-" . $image->getClientOriginalName();
$width = $width > 600 ? 600 : $width;
$height = $height > 600 ? $width * $ratio : $height;
Image::make($image->getRealPath())->resize($width, $height)->save(public_path() . '/img/pncpictures/' . $filename);
$comment->image = 'img/pncpictures/' . $filename;
} else {
$comment->image = '';
}
if ($tag != 'default') {
$comment->addTagOrCreateNew($tag, $inputs['user_id']);
}
$post->comments()->save($comment);
$comment->updateComment(1);
/* redirect back to the form portion of the page */
return Redirect::to(URL::previous() . '#reply')->with('success', trans('messages.CHBS'));
} else {
return Redirect::to(URL::previous() . '#reply')->withErrors($valid)->withInput();
}
}
示例8: Post
MTConnect Blog:
http://localhost/rousseau/generic_fb_app/comments.php?blog_xid=6a00e5539faa3b88330120a94362b9970b&permalink=http://mtcs-demo.apperceptive.com/testmt/animals/2010/03/sea-otter.php&fb_id=fb-animals-60
MTConnectBlog:
http://dev3.apperceptive.com/rousseau/comments.php?blog_xid=6a00e5539faa3b88330120a94362b9970b&permalink=http://mtcs-demo.apperceptive.com/testmt/animals/2010/03/sea-otter.php&fb_id=fb-animals-60&HTML=1
Standard TypePad Blog:
http://dev3.apperceptive.com/rousseau/comments.php?xid=6a00e5539faa3b883301310f284ed8970c&permalink=http://nataliepo.typepad.com/hobbitted/2010/02/some-ill-shit-is-overdue-in-the-hobbit-right-about-now.html&fb_prefix=braided_comments-&HTML=1
*/
require_once 'rousseau-includes/rousseau-utilities.php';
start_db_connection();
//$post = new Post($_POST);
$post = new Post($_GET);
$comments = $post->comments();
/*
debug ("<h2>GET table:</h2>");
print_as_table($_GET);
debug("<h2>POST table:</h2>");
print_as_table($_POST);
*/
//if (array_key_exists('HTML', $_POST)) {
if (array_key_exists('HTML', $_GET)) {
foreach ($comments as $comment) {
echo ' <div class="comment-outer">
<div class="comment-avatar">
<a href="' . $comment->author->profile_url . '"><img class="avatar" src="' . $comment->author->avatar . '" /></a>
</div>
<div class="comment-contents">
示例9: testCommentsIsAMorphMany
public function testCommentsIsAMorphMany()
{
$post = new Post();
$this->assertInstanceOf('Illuminate\\Database\\Eloquent\\Relations\\MorphMany', $post->comments());
}