雄辩的地方堆积

时间:2020-09-15 08:37:55

标签: php laravel eloquent

我的问题如下所示

$data = Model::whereRaw(<condition 1>)
$data1 = $data->whereRaw(<condition 2>)
$data2 = $data->whereRaw(<condition 3>)

每当我打印$data2->toSql()时,我都会得到这个

select * from table where <condition 1> and <condition 2> and <condition 3>

代替

select * from table where <condition 1> and <condition 2>

2 个答案:

答案 0 :(得分:2)

因为$ data,$ data1,$ data2指针指向内存中的同一对象...

解决此问题:

$data = Model::whereRaw(<condition 1>);

$data1 =(clone $data)->whereRaw(<condition 2>)

$data2 = (clone $data)->whereRaw(<condition 3>)

答案 1 :(得分:-1)

尝试

$currentLanguage = 'es';
// If the TargetLanguageCode is not "en", the SourceLanguageCode must be "en".
$targetLanguage= 'en';
$textToTranslate = 'El AWS SDK for PHP versión 3 permite a los desarrolladores de PHP utilizar Amazon Web Services en su código PHP y crear aplicaciones y software robustos utilizando servicios como Amazon S3, Amazon DynamoDB, Amazon Glacier, etc. Puede empezar rápidamente instalando el SDK mediante Composer (solicitando el paquete aws/aws-sdk-php) o descargando el archivo aws.zip o aws.phar independiente';
try {
$translate = $this->aws_utils->getTranslate();
$result = $translate->translateText(array(
'SourceLanguageCode' => $currentLanguage,
'TargetLanguageCode' => $targetLanguage,
'Text' => $textToTranslate
));
}catch (AwsException $e) {
// output error message if fails
var_dump($e->getMessage());die;
}