有点讨厌一个方法做完所有事情的
public function payHello()
{
$user = User::With('puser')->find(1);
//用户奖金
$user->money = 100;
$user->save();
//一级
if(! is_null($user->puser)){
...一堆代码
}
//二级
if(! is_null($user->puser->puser)){
...一堆代码
}
}
实际的代码120+行,增加一个店铺收益,测试非常的麻烦。
阅读也不爽,还要全读完。
public function payHello()
{
$this->user = User::With('puser')->find(User::id());
$this->oneMOney();
$this->twoMOney();
$this->shopMOney();
}
我控制器主方法 行数的感觉
0 - 3 舒适,这种肯定复用了的
3 - 6 增删改 有点小复杂
6 - 20 麻烦的逻辑
20+ 难看
100 痛苦
推荐文章: