为什么存储在变量方法范围中的 Laravel Builder 对象可以被同一类中的另一个方法修改?

问题描述

假设有一个名为 ReportType 的模型,其中包含一些字段(id、name、created_at)。

在我的控制器中 (ReportTypeController.PHP)

<?PHP

namespace App\Http\Controllers;

class HomeController extends Controller
{

    public function index()
    {
        $reportType = ReportType::whereNotNull('created_at');

        $this->addSomeConditions($reportType);

        return $reportType;
    }

    private function addSomeConditions($reportType)
    {
        $reportType->whereIn('id',[1,2,3]);
    }

}

索引中的 $reportType 变量将具有来自方法 whereInaddSomeConditions 条件,即使 $reportType 没有通过引用传递并且 addSomeConditions 方法没有任何返回值。类构建器是否正在实现单例,该类中将只有一个活着的对象?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)