Permalink
Browse files

建立 PostService (使用 Null Object 模式)

  • Loading branch information...
1 parent 3322798 commit 99aea8c60702e4c1a6bf753689ea3139ad242e2b @oomusou committed Jul 13, 2016
Showing with 1 addition and 1 deletion.
  1. +1 −1 app/Services/PostService.php
@@ -25,7 +25,7 @@ public function __construct(PostRepository $postRepository)
* @param string $default
* @return string
*/
- public function showTitle(int $id, string $default)
+ public function showTitle(int $id, string $default = '')
{
return $this->postRepository->getTitle($id, $default)->title;
}

1 comment on commit 99aea8c

@ricoa
ricoa commented on 99aea8c Aug 17, 2016

有个问题是,加入id为1的数据不存在,而我获取id为1的title,用空对象的话就会返回‘’,这样我会以为id为1数据存在,后续操作也会以此为前提,例如更新数据,这是一个错误的逻辑。

Please sign in to comment.