コード例 #1
0
ファイル: Comment.php プロジェクト: php-soft/laravel-comments
 /**
  * Create the model in the database.
  *
  * @param  array  $attributes
  * @return comment
  */
 public static function create(array $attributes = [])
 {
     $comment = new Comment($attributes);
     $comment->user_id = Auth::user()->id;
     $comment->save();
     return $comment;
 }
コード例 #2
0
 public function testBrowseNotFound()
 {
     // test not login
     $urlencode = urlencode('http://pm.greenglobal.vn/post1');
     $res = $this->call('GET', "/comments/{$urlencode}");
     $this->assertEquals(401, $res->getStatuscode());
     // test no record
     $user = factory(App\User::class)->create();
     Auth::login($user);
     $urlencode = urlencode('http://pm.greenglobal.vn/post1');
     $removeAllComments = Comment::truncate();
     $res = $this->call('GET', "/comments/{$urlencode}");
     $this->assertEquals(200, $res->getStatusCode());
     $results = json_decode($res->getContent());
     $this->assertEquals(0, count($results->entities));
     // test url no match
     for ($i = 0; $i < 10; ++$i) {
         $comments[] = factory(Comment::class)->create(['url' => 'http://pm.greenglobal.vn/1', 'user_id' => '1']);
     }
     $urlencode = urlencode('http://pm.greenglobal.vn/2');
     $res = $this->call('GET', "/comments/{$urlencode}");
     $this->assertEquals(200, $res->getStatusCode());
     $results = json_decode($res->getContent());
     $this->assertEquals(0, count($results->entities));
 }
コード例 #3
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index($url)
 {
     $comments = Comment::browse(['limit' => $limit = (int) Input::get('limit', 25), 'cursor' => Input::get('cursor'), 'offset' => (Input::get('page', 1) - 1) * $limit, 'url' => $url]);
     return response()->json(arrayView('phpsoft.comments::comment/browse', ['comments' => $comments]), 200);
 }