小编Sag*_*ing的帖子

Pluck id(整数)强制转换为字符串Laravel

从数据库中提取时,我得到id了字符串.

$alphabets = new Alphabet();
return $alphabets->pluck('name', 'id');
Run Code Online (Sandbox Code Playgroud)

产量

{
    "1": "Apple",
    "2": "Ball",
    "3": "Cat"
}
Run Code Online (Sandbox Code Playgroud)

预期

{
    1: "Apple",
    2: "Ball",
    3: "Cat"
}
Run Code Online (Sandbox Code Playgroud)

但是,当我扭转IDname,

return $alphabets->pluck('id', 'name');
Run Code Online (Sandbox Code Playgroud)

我得到id为整数.

{
    "Apple": 1,
    "Ball": 2,
    "Cat": 3
}
Run Code Online (Sandbox Code Playgroud)

我不确定幕后发生了什么.但是我如何获得整数ID?实际上,旧的flash会话因为1 vs "1"Form Collective 而没有设置值.

{!! Form::select('alphabet', $alphabets, null, ['class' => 'form-control', 'multiple' => true]) !!}
Run Code Online (Sandbox Code Playgroud)

php forms json laravel pluck

8
推荐指数
2
解决办法
5510
查看次数

如何获得 redux-saga 动作的响应?

我正在尝试获得redux-saga从服务返回的操作响应。这些是我的项目的一些片段。

// ACTION

const actions = {
  LOAD_CURRENT_ACCOUNT: 'user/LOAD_CURRENT_ACCOUNT'
};

export const currentUser = () => ({
  type: actions.LOAD_CURRENT_ACCOUNT
});

Run Code Online (Sandbox Code Playgroud)
// SERVICE

export async function currentAccount() {
  try {
    const url = config.endpoints.user;
    const res = await http.get(url);

    return res.data;
  } catch (err) {
    if (err.response && err.response.data) {
      notification.warning({
        message: err.response.data.code,
        description: err.response.data.message
      });
    }

    return false;
  }
}
Run Code Online (Sandbox Code Playgroud)
// SAGA

export function* LOAD_CURRENT_ACCOUNT() {
  const res = yield call(currentAccount);

  if (res) {
    yield put({
      type: actions.SET_STATE, …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs redux-saga

5
推荐指数
0
解决办法
1486
查看次数

如何在 SQL Server 中聚合 JSON?

我查看了 SQL Server 文档,但没有找到类似 JSON 聚合的内容。这是我的表的结构。

| Column Name         | Type               | Nullable | Properties | Description |
| ------------------- | ------------------ | -------- | ---------- | ----------- |
| employee_id         | INT(4)             | NO       |            |             |
| first_name          | NVARCHAR(100)      | NO       |            |             |
| last_name           | NVARCHAR(100)      | NO       |            |             |
| department_id       | INT(4)             | NO       |            |             |
| date                | DATETIMEOFFSET(10) | NO       |            |             |
Run Code Online (Sandbox Code Playgroud)

我期待的是:

{
    department_id: 1,
    count: 2, …
Run Code Online (Sandbox Code Playgroud)

sql t-sql sql-server

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

Laravel中间件的顺序(Middleware Priority)。使用Postgres的多租户

web.php中,随着发出HTTP请求的子域类型,我在中间件中切换了Postgres模式。这条路:

Route::group(
    [
        'domain'     => '{tenant}.' . config('app.url'),
        'middleware' => 'select-schema'
    ],
    function () {
        $this->get('/', 'HomeController@index')->middleware('auth');
    }
);
Run Code Online (Sandbox Code Playgroud)

选择模式中间件中,我这样做。这可以正常工作。(不用担心)

DB::select('SET search_path TO ' . {tenant});
Run Code Online (Sandbox Code Playgroud)

我的主要问题是:migrations对于public方案和任何其他方案,我都有所不同individual tenant。在individual tenant我有users桌子。一旦我登录,就会弹出此错误。

SQLSTATE [42P01]:未定义表:7错误:关系“用户”不存在

主要问题是

$this->get('/', 'HomeController@index')->middleware('auth');
Run Code Online (Sandbox Code Playgroud)

该模型运行良好,但中间件auth先执行 select-schema

我该如何订购? select-schema然后auth

php postgresql middleware multi-tenant laravel

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