小编bl4*_*sta的帖子

在php上的compact()vs手动数组声明

我通常使用compact()php的函数来从变量构建数组.另外,我可以手动创建该数组.这些用法有任何优点或缺点吗?我将在以下部分中分享这两个声明的示例:

紧凑的用法

   <?php 
    $name = "John";
    $surname = "Doe";
    compact('name','surname');
?>
Run Code Online (Sandbox Code Playgroud)

输出:

['name'=>'John','surname'=>'Doe']
Run Code Online (Sandbox Code Playgroud)

手动阵列声明

<?php 
$name = "John";
$surname = "Doe";
$data = array("name"=>$name,"surname"=>$surname);
?>
Run Code Online (Sandbox Code Playgroud)

输出:

['name'=>'John','surname'=>'Doe']
Run Code Online (Sandbox Code Playgroud)

php arrays

6
推荐指数
2
解决办法
1300
查看次数

如何在vuex模块上定义吸气剂?

我正在尝试改善vuex模块,但出现以下错误:

Uncaught Error: [vuex] getters should be function but "getters.getComments" in module "comments" is [].
Run Code Online (Sandbox Code Playgroud)

/stores/comments.js(模块)

import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const state = {
    comments: []
}

const getters = {
    getComments: state => state.comments
}
const mutations = {
    setComments(state, comments) {
        state.comments = comments
    }
}

const actions = {
    setComments(context, data) {
        context.commit('setComments', data)
    }
}
export default new Vuex.Store({
    state,
    getters,
    mutations,
    actions
})
Run Code Online (Sandbox Code Playgroud)

这是我的store.js,其中包含vuex store.js的根状态

import Vue from …
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vuex

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

Elasticsearch 基于嵌套对象的过滤和计数操作

我是弹性搜索的新手。尝试将其用于分析计算。我不知道,是否可以这样做,但是,我正在尝试寻找购买次数为 0 的客户。我将订单存储为每个客户的嵌套对象数组。在这里,您可能会找到客户索引的示例映射属性:

"first_name" => [
 "type" => "text"
],
"last_name" => [
    "type"=> "text"
],
"email" => [
    "type"=> "text"
],
"total_spent" => [
    "type"=> "text"
],
"aov" => [
    "type"=> "float"
],
"orders_count" => [
    "type"=> "integer"
],
"orders" => [
    "type" => "nested",
    "properties" => [
        "order_id" => [
            "type"=>"text"
        ],
        "total_price" => [
            "type"=>"float"
        ]
    ]
]
Run Code Online (Sandbox Code Playgroud)

示例客户索引:

    [
   {
      "_index":"customers_index",
      "_type":"_doc",
      "_id":"1",
      "_score":1,
      "_source":{
         "first_name":"Stephen",
         "last_name":"Long",
         "email":"egnition_sample_91@egnition.com",
         "total_spent":"0.00",
         "aov":0,
         "orders":[]
      }
   },
   {
      "_index":"customers_index",
      "_type":"_doc", …
Run Code Online (Sandbox Code Playgroud)

php elasticsearch

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

使用FacetFilters进行Laravel Scout搜索?

如您所知,where()在搜索方法使用后使用语句numericFilter.我试图用字符串过滤过滤我的搜索结果.

如何在搜索语句中使用Facet Filter?

php laravel algolia laravel-scout

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

Laravel 通知未广播而没有任何错误?

我正在尝试使用 Laravel 和 Vue JS 实现一个通知系统。我实现了一切,它需要工作,但通知类没有广播。

.env 文件

BROADCAST_DRIVER=pusher
PUSHER_APP_ID=40xxxx
PUSHER_KEY=5a6axxxxxx
PUSHER_SECRET=b35xxxxxx
Run Code Online (Sandbox Code Playgroud)

已经运行以下命令:

npm install --save laravel-echo pusher-js
composer require pusher/pusher-php-server "~2.6"
Run Code Online (Sandbox Code Playgroud)

在 app.js 中(未注释)

App\Providers\BroadcastServiceProvider::class,
Run Code Online (Sandbox Code Playgroud)

广播服务提供商.php

Broadcast::channel('App.User.*', function ($user, $userID) {
            return (int) $user->id === (int) $userID;
        });
Run Code Online (Sandbox Code Playgroud)

bootstrap.js

import Echo from "laravel-echo"
 window.Pusher = require('pusher-js');
 window.Echo = new Echo({
    broadcaster: 'pusher',
    key: '5a6axxxxxx',
    cluster: 'eu',
    encrypted: true,
    authEndpoint: "/broadcasting/auth"
 });
 window.Pusher.log = function(message){
    window.console.log(message);
 }
 window.Echo.private('App.User.1')
    .notification((notification) => {
        console.log(notification.type);
 });
Run Code Online (Sandbox Code Playgroud)

Laravel 日志中没有错误。与此同时,我正在检查 Pusher 的调试控制台上仅连接和断开连接的请求。为什么它没有推送任何类型的错误以及为什么它不能正常工作?

php laravel pusher laravel-echo

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