gpt4 book ai didi

php - Laravel 克隆查询字符串

转载 作者:可可西里 更新时间:2023-10-31 22:44:29 28 4
gpt4 key购买 nike

是否可以克隆一个查询字符串,这样我就可以编写一次并在不影响其他结果的情况下进行长时间的更改?

$query = DB::table('users')
->where('id', '=', '123');

$queryGet = $query;
$queryPaginate = $query;
$queryCount = $query;

if(Input::has('get'))
$queryGet = $queryGet->get();

if(Input::has('paginate'))
$queryPaginate = $queryPaginate->paginate(25);

if(Input::has('count'))
$queryCount = $queryCount->count(DB::raw('Distinct users.*'));

因为现在,分页将更改第一个 get()。

谢谢

最佳答案

你的词汇完全正确 :) 在 PHP5+ 中,尝试克隆:

<?php
$queryGet = clone $query;
$queryPaginate = clone $query;
$queryCount = clone $query;

http://php.net/manual/en/language.oop5.cloning.php

关于php - Laravel 克隆查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27625411/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com