小编mnv*_*mnv的帖子

在laravel中编写一个查询join sum groupby


请帮我写查询。
我有 2 个表:“项目”和“债务”
“债务”表有

id | project_id | currency_list | total
1  | 1          | 1             | 1000
2  | 1          | 2             | 500
3  | 2          | 1             | 1000
4  | 2          | 2             | 500
...
Run Code Online (Sandbox Code Playgroud)

我需要编写查询以从项目中获取 1000 行,并将所有“总计”与“currency_list”组相加

非常感谢 :)

join sum laravel

4
推荐指数
1
解决办法
2万
查看次数

拉拉维尔。两个项目的公共队列

我有两个不同的项目。Laravel 项目 A 和 Laravel 项目 B。我需要通过队列从项目 A 到项目 B 创建任务。我不想在项目 A 中为此创建工作。

目前我的认识是:

项目A

有状态但没有业务逻辑的工作:

<?php

namespace App\Jobs;

use ...;

/**
 * Fake class!!!
 */
class MyJob extends Job implements ShouldQueue
{
    use InteractsWithQueue, SerializesModels;

    public $queue = 'MyQueue';

    /**
     * Some state
     */
    protected $_contentId;

    public function __construct($contentId)
    {
        $this->_contentId = $contentId;
    }

    /**
     * Excess. I dont need business logic in project A.
     */
    public function handle()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

我在项目 A 中将作业推入队列:

    ...
    $this->dispatch(
        new MyJob($this->_contentId) …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-5.2

3
推荐指数
1
解决办法
1774
查看次数

如何使用文本和标签创建元素?

我已经创建了下一个 XML:

item = E('p') # <p/>
Run Code Online (Sandbox Code Playgroud)

现在我需要将下一个内容放入其中:

text = "some <bold>text</bold>"

# item.append(text) 
# TypeError: Argument 'element' has incorrect type (expected lxml.etree._Element, got str)

# item.append(fromstring(text)) 
# lxml.etree.XMLSyntaxError: Start tag expected, '<' not found, line 1, column 1
Run Code Online (Sandbox Code Playgroud)

结果我需要下一个 XML 节点:

<p>some <bold>text</bold></p>
Run Code Online (Sandbox Code Playgroud)

如何正确地做到这一点?

python lxml python-3.x

3
推荐指数
1
解决办法
3536
查看次数

建立失败,但工作状态是Gitlab的成功

我的Dockerfile:

FROM mm_php:7.1

ADD ./docker/test/source/entrypoint.sh /work/entrypoint.sh
ADD ./docker/wait-for-it.sh /work/wait-for-it.sh
RUN chmod 755 /work/entrypoint.sh \
    && chmod 755 /work/wait-for-it.sh

ENTRYPOINT ["/work/entrypoint.sh"]
Run Code Online (Sandbox Code Playgroud)

entrypoint.sh:

#!/bin/bash -e

/work/wait-for-it.sh db:5432 -- echo "PostgreSQL started"

./vendor/bin/parallel-phpunit --pu-cmd="./vendor/bin/phpunit -c phpunit-docker.xml" tests
Run Code Online (Sandbox Code Playgroud)

泊坞窗,compose.yml:

version: '2'
services:

  test:
    build:
      context: .
      args:
        ssh_prv_key: ${ssh_prv_key}
        application_env: ${application_env}
      dockerfile: docker/test/source/Dockerfile
    links:
      - db

  db:
    build:
      context: .
      dockerfile: docker/test/postgres/Dockerfile
    environment:
      PGDATA: /tmp
Run Code Online (Sandbox Code Playgroud)

.gitlab-ci.yml:

image: docker:latest

services:
  - name: docker:dind
    command: ["--insecure-registry=my.domain:5000 --registry-mirror=http://my.domain"]

before_script:
  - apk add --no-cache py-pip
  - pip install …
Run Code Online (Sandbox Code Playgroud)

gitlab docker gitlab-ci gitlab-ci-runner docker-compose

2
推荐指数
1
解决办法
632
查看次数

如何为 Symfony 迁移指定名称?

我尝试使用 Symfony 创建新的迁移:

$ php app/console doctrine:migrations:generate
Generated new migration class to "/path/to/project/app/DoctrineMigrations/Version20100621140655.php"
Run Code Online (Sandbox Code Playgroud)

但我想用 nameVersion20100621140655_MyName.php而不是Version20100621140655.php. 我怎样才能做到这一点?

编辑

链接主题:https : //github.com/doctrine/migrations/issues/487

php symfony

1
推荐指数
1
解决办法
951
查看次数

使用“?|”执行查询 操作员

我有my_table带有jsonb列的表sentiments。我需要从此列中删除所有键“10216”和“10191”。

我尝试在 Laravel 中做下一步:

DB::table('my_table')
    ->whereRaw("sentiments ?| ARRAY['10216', '10191']")
    ->update([
        'sentiments' => DB::raw("sentiments - '10216' - '10191'")
    ]);
Run Code Online (Sandbox Code Playgroud)

但我有下一个错误:

[Illuminate\Database\QueryException]                                                                                 
  SQLSTATE[42601]: Syntax error: 7 ??????:  ?????? ?????????? (????????? ?????????: "$1")                              
  LINE 1: ...= sentiments - '10216' - '10191' where sentiments $1| ARRAY[...                                           
                                                               ^ (SQL: update "my_table" 
    set "sentiments" = sentiments - '10216' - '10191' 
    where sentiments ?| ARRAY['10216', '10191'])
Run Code Online (Sandbox Code Playgroud)

因为正如我所看到的“?” 看起来像参数。如何逃避这个符号?

更新

我也试着写两个问题sentiments ??| ARRAY::

[Illuminate\Database\QueryException]                                                                                 
  SQLSTATE[42883]: Undefined function: 7 ??????:  ???????? …
Run Code Online (Sandbox Code Playgroud)

php postgresql pdo laravel laravel-5.3

0
推荐指数
1
解决办法
461
查看次数