AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-10873713

mstdmstd's questions

Martin Hope
mstdmstd
Asked: 2025-04-11 22:50:53 +0800 CST

无法使用折叠功能将数据收集到一个数组中

  • 7

在 Laravel 10 / PHP 8.2 应用程序中,我尝试使用collapse设置请求将数据收集到一个数组中,其中一些参数发生了更改:

$data = []

FOR(...
        $data = Arr::collapse($data, $query->where('some_field', $someParameter)->get()->toArray())



ENDFOR,

但这不起作用,结果数组为空。那么我需要使用其他方法吗collapse?

  • 1 个回答
  • 49 Views
Martin Hope
mstdmstd
Asked: 2025-04-10 20:00:44 +0800 CST

如何向Carbon值中添加其他时间字段?

  • 5

在 laravel 10 / php 8.2 时间中我有一个时间字段,并且在模型中我定义了转换:

<?php

namespace App\Casts;

use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Database\Eloquent\Model;

class TimeCast implements CastsAttributes
{
    public function get(Model $model, string $key, mixed $value, array $attributes): mixed
    {
        return  Carbon::parse($value)->format('H:i');
    }

    public function set(Model $model, string $key, mixed $value, array $attributes): mixed
    {
        return $value;
    }
}

在 Item 模型中:

protected function casts(): array
{
    return [
        'time' => TimeCast::class,
    ];
}

我需要 Carbon 值(时间为零)来添加其他时间字段。我这样做:

$calcDate = Carbon::parse(Carbon::now(\config('app.timezone')))->startOfDay();
$calcDate->addDays(5);

$item = Item::find($id);
$dateTill = $calcDate->addMinutes($item->time);
dd(Carbon::parse($dateTill));
            

但在 $dateTill 中我只看到 $calcDate 值(+5 天,不含时间)。

我该怎么做?

  • 2 个回答
  • 51 Views
Martin Hope
mstdmstd
Asked: 2025-03-06 00:30:04 +0800 CST

如何正确地将辅助文件添加到 laravel 应用程序中?

  • 5

我需要将helper.php文件添加到我的 laravel 10 应用程序中,并将其添加到autoload-dev块中:

   "autoload": {
        "psr-4": {
            "App\\": "app/",
            "Database\\Factories\\": "database/factories/",
            "Database\\Seeders\\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "files": [
            "app/Library/helper.php"
        ],
        "psr-4": {
            "Tests\\": "tests/"

这就引发了一个问题:它的位置正确吗?有什么autoload-dev区别autoload?

laravel
  • 1 个回答
  • 31 Views
Martin Hope
mstdmstd
Asked: 2025-03-03 21:15:26 +0800 CST

为什么 js 代码中的异步 inertiajs 请求不起作用?

  • 5

我有 Laravel 11 / vuejs 3 / element-plus 2.9.5” 应用程序,我请求从我的 vue 文件保存表单:

    const onSubmit = () => {
        console.log(editMode.value)

        if (editMode.value) {
            console.log(form.title) // I SEE THIS MESSAGE
            const updateTask = async () => {

                // BUT I DO NOT SEE THESE MESSAGES BELOW_AND_NO_REQUEST_TO_SERVER
                console.log('form.title::')
                console.log(form.title)

                console.log('form.id::')
                console.log(form.id)

                const formData = new FormData();
                formData.append('title', form.title);
                ...
                formData.append("_method", 'PUT');

                try {
                    await router.post(router('admin.tasks.update', form.id), formData, {
                        preserveUrl: true,
                        preserveState: true,
                        preserveScroll: true,
                        onSuccess: (page) => {
                            console.log('UPDATE page::')
                            console.log(page)

                            resetFormData();
                            Swal.fire({
                                toast: true,
                                icon: "success",
                                position: "top-end",
                                showConfirmButton: false,
                                title: page.props.flash.success
                            });
                        }
                    })
                    console.log('AFTER UPDATE::')

                } catch (err) {
                    console.log(err)
                }
            }
        }// editMode.value

    }  // const onSubmit = () => {

我在网上找到了这个例子——我应该发出异步请求吗?

什么代码是正确的?

我的想法是:我实际上不需要定义 updateTask 方法或在调用请求方法时使用异步:

更新区块:

所以我重建了 onSubmit :

const onSubmit = () => {
    if (editMode.value) {

            console.log('form.id::')
            console.log(form.id)


            const formData = new FormData();
            formData.append('title', form.title);
            formData.append('task_category_id', form.task_category_id);
            formData.append('priority', form.priority);

            formData.append('content', form.content);
            formData.append('completed', form.completed);
            formData.append('deadline_at', form.deadline_at);
            formData.append("_method", 'PUT');

            router.post(router('admin.tasks.update', form.id), formData, {
                    preserveUrl: true,
                    preserveState: true,
                    preserveScroll: true,
                    onSuccess: (page) => {
                        console.log('UPDATE page::')
                        console.log(page)

                        resetFormData();
                        Swal.fire({
                            toast: true,
                            icon: "success",
                            position: "top-end",
                            showConfirmButton: false,
                            title: page.props.flash.success
                        });
                    }
                })
            console.log('AFTER UPDATE::')

    }// editMode.value

}  // const onSubmit = () => {

但是我得到了错误:

在此处输入图片描述

这是什么错误以及如何修复?

inertiajs
  • 1 个回答
  • 22 Views
Martin Hope
mstdmstd
Asked: 2025-02-19 21:31:11 +0800 CST

为什么我在 vue 页面中使用 VueAwesomePaginate 时出错?

  • 5

我已将 peshanghiwa/vue-awesome-paginate 添加到我的 laravel 11 /vuejs 3 应用程序中,并在 resources/js/app.js 中声明了 VueAwesomePaginate:

import VueAwesomePaginate from "vue-awesome-paginate";
import "vue-awesome-paginate/dist/style.css";

// Vue.component("broadcaster", require("./components/Broadcaster.vue").default);
// Vue.component("viewer", require("./components/Viewer.vue").default);


const appName = import.meta.env.VITE_APP_NAME || 'Laravel';

import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import Multiselect from '@vueform/multiselect'

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) =>
        resolvePageComponent(
            `./Pages/${name}.vue`,
            import.meta.glob('./Pages/**/*.vue'),
        ),
    setup({ el, App, props, plugin }) {
        return createApp({ render: () => h(App, props) })
            .use(plugin)
            .use(ZiggyVue)
            .use(ElementPlus)
            .component('inertia-link', Link)
            .component('vue-awesome-paginate', VueAwesomePaginate)
            .component('file-upload', VueUploadComponent)
            .component('multiselect', Multiselect)
            .mount(el);
    },
    progress: {
        color: '#4B5563',
    },
});

但是当我在 vue 文件中使用它时:

<template>
    ...
    <div class="p-2" v-show="totalTicketsCount > 1">
        <vue-awesome-paginate
            :total-items="totalTicketsCount"
            :items-per-page="backendItemsPerPage"
            :max-pages-shown="5"
            v-model="currentPage"
            @click="paginateClick"
        />
    </div>

</template>

在上面的文件中我没有声明分页组件 - 我认为它必须是全局的......

我在控制台中看到错误:

app.js:44 [Vue warn]: Component is missing template or render function:
{install: ƒ}

  at <VueAwesomePaginate total-items=8 items-per-page=2 max-pages-shown=5  ... >
  at <PersonalLayout>
  at <PersonalTicketsList errors=
{}
 auth=
{user: {…}, loggedUserIsAdmin: false, loggedUserIsManager: false, loggedUserIsSalesperson: false}
 ziggy=
... 

 

并且分页不可见。

我该如何定义组件才能使其工作?

laravel
  • 1 个回答
  • 24 Views
Martin Hope
mstdmstd
Asked: 2024-12-20 17:38:29 +0800 CST

如何在 PhpStorm 2024 中更改不存在的类的背景颜色?

  • 5

在 PhpStorm 中,我的 php 代码因未定义类而出现错误:

在此处输入图片描述

在哪里可以更改背景颜色以便更清楚地看到错误?现在我几乎无法区分错误的背景颜色……

我在设置选项中搜索,但没有找到。

我使用最新的 PhpStorm 2024.2 版本。

phpstorm
  • 1 个回答
  • 16 Views
Martin Hope
mstdmstd
Asked: 2024-12-16 23:21:35 +0800 CST

为什么从 FrankfurterService 或 ExchangeRateHost 导入的货币汇率不同?

  • 4

在 Laravel 11 应用程序中,我从 FrankfurterService 或 ExchangeRateHost 导入货币汇率,切换不同的服务实现检索结果并比较数据,得到的结果略有不同。

首先,我认为差异在于它们以不同的“模式”显示货币汇率:“我们买入”/“我们交易”

之后,一个问题是,如果这个“模式”显示在文档的某个地方

https://exchangerate.host/documentation

和

https://github.com/brunoinds/frankfurter-laravel

?

我没有找到...

我检查了一些货币的结果:

在此处输入图片描述

我发现它们有点不同。不确定是“我们购买”/“我们交易”的“模式”还是其他什么?

在这两种情况下,我都显示“源”货币 - “CAD”

laravel
  • 1 个回答
  • 26 Views
Martin Hope
mstdmstd
Asked: 2024-12-08 05:28:19 +0800 CST

为什么运行 Composer 时出现与约束不匹配的错误

  • 5

我需要使用 Composer 文件中定义的 laravel 应用程序运行:

"require": {
    "php": "^8.1",
    "laravel/framework": "^10.0",
    "tatumio/tatum-php": "^2.0",

在我的 php8.3 和 apache 2 上

但作曲家提出了一个错误:

Problem 1
- Root composer.json requires tatumio/tatum-php ^2.0, found tatumio/tatum-php[dev-master] but it does not match the constraint.

但为什么我会收到这个错误?

存储库https://github.com/tatumio/tatum-php现已存档,在作曲家中我看到

"minimum-stability": "stable",
"prefer-stable": true

但dev-master在错误信息中......

我如何运行该应用程序?

其他详细信息:

在文件中composer.json我添加了一个块:

"repositories": [
    {
        "type": "vcs",
        "url": "https://github.com/markjivko/tatum-php"
    }
],

不确定type="vcs"这里是否有效。我还修改了该require块:

"require": {
    "php": "^8.1",
    "laravel/framework": "^10.0",
    "markjivko/tatum-php": "master",
},

我认为对于包来说markjivko/tatum-php有效值是master,但是为什么会出现错误以及哪个是有效的语法?

laravel
  • 1 个回答
  • 35 Views
Martin Hope
mstdmstd
Asked: 2024-12-03 17:16:07 +0800 CST

为什么使用 spatie/laravel-tags 数据保存的标签有不同的 slug 和 type 字段?

  • 5

阅读如何在 laravel 11 应用程序 https://spatie.be/docs/laravel-tags/v4/basic-usage/using-tags中手动使用 spatie 标签

我已经安装了 spatie/laravel-tags 4.7 包保存标签我使用的方法:

$article->syncTags($this->selectedTags, 'article');

但是保存的数据具有不同的格式,我在启动应用程序时在种子中添加了这些数据:

Tag::findOrCreate(['film'], 'article');

我在 slug 和 type 字段中看到不同的值:

在此处输入图片描述

看起来 syncTags 方法 slug 和 type 字段以不同的方式填充?

什么问题?如何修复?

laravel
  • 1 个回答
  • 15 Views
Martin Hope
mstdmstd
Asked: 2024-11-10 22:36:34 +0800 CST

当头像字段为空或找不到文件时如何显示默认头像?

  • 5

在 Laravel 10 / Nova 4.27 应用程序中,我在用户资源中定义了一个头像字段:

Image::make(__('Avatar'), 'avatar')
    ->disk('local')
    ->path('public/avatars')
    ->prunable()
    ->deletable(true),

当头像字段为空或找不到文件时,如何显示位于 public/img 中的默认头像?

laravel-nova
  • 1 个回答
  • 13 Views
Martin Hope
mstdmstd
Asked: 2024-10-05 12:52:23 +0800 CST

为什么用 Carbon 格式化的日期无效?

  • 6

为什么在 Laravel 11 / php 8.2 应用程序中运行代码

$minDay = CurrencyHistory::select(DB::raw('MIN(day) as min_day'))->first()->min_day;
\Log::info($minDay);
\Log::info(Carbon::createFromTimestamp(strtotime($minDay))->format('j F, Y'));

我看到结果:

[2024-10-05 07:30:08] local.INFO: 2024-09-28
[2024-10-05 07:30:08] local.INFO: 27 September, 2024

因此最短天数是2024-09-28,但我所拥有的表格上的结果值是27 September, 2024

在货币历史模型中我有:

protected $casts = [
        'created_at' => 'datetime', 'updated_at' => 'datetime', 'value' => HistoryMoney::class, 'day' => 'date'
    ];

跟踪 SQL 我有:

   SELECT MIN(day)     AS min_day
    FROM `currency_histories` limit 1

它确实返回了价值2024-09-28。

格式 'j F, Y' 无效吗?格式相同format('d F, Y',结果相同...我该使用哪种格式?

  • 1 个回答
  • 38 Views
Martin Hope
mstdmstd
Asked: 2024-10-02 21:47:02 +0800 CST

如何向 json 值字段添加多个值并在 json 字段中形成一个平面数组?[重复]

  • 4
此问题这里已有答案:
PHP 将一个数组附加到另​​一个数组(不是array_push或+) (11个答案)
1 小时前关闭。

在 laravel 11 / php 8.2 应用程序中,我需要向 UserOption 模型的 json 值字段添加几个值,我使用代码完成此操作:

array_push($this->selectedCurrencies, array_values($userOption->value));
$userOption->value = array_values($this->selectedCurrencies);
$userOption->save();

但是在值字段中我看到的是新元素和旧值的子数组,而不是我需要的平面数组?

如何修复它?

  • 2 个回答
  • 46 Views
Martin Hope
mstdmstd
Asked: 2024-02-24 22:38:30 +0800 CST

为什么httpClient的$response->getBody()返回NULL?

  • 4

我尝试使用 Http::get 方法从https://climate-api.open-meteo.com服务获取数据,但运行请求方法 getBody 返回 null,而不是数据数组:

$response = Http::get('https://climate-api.open-meteo.com/v1/climate', [
'query' => [
'latitude' => $latitude,
'longitude' => $longitude,
'start_date' => $from->format('Y-m-d'),
'end_date' => $to->format('Y-m-d'),
]
]);

// RETURNS TRUE
\Log::info(varDump($response->successful(), ' -10 $response->successful()::'));


// RETURNS 200
\Log::info(varDump($response->getStatusCode(), ' -11 $response->getStatusCode()::'));


// RETURNS NULL
\Log::info(varDump(json_decode($response->getBody(), true), ' -12 $response->getBody()::'));

发出示例请求,例如:

https://climate-api.open-meteo.com/v1/climate?latitude=40.4165&longitude=-3.7026&start_date=2023-07-09&end_date=2023-07-11&models=CMCC_CM2_VHR4&daily=temperature_2m_max

我获得了有效的数据结构,但没有看到我在 $response->getBody() 方法中获得了无效数据?

laravel
  • 1 个回答
  • 19 Views
Martin Hope
mstdmstd
Asked: 2024-01-25 13:25:09 +0800 CST

如何在正则表达式中检查“;”之前没有空格 在线上?[复制]

  • 4
这个问题在这里已经有了答案:
匹配 PHP 中多行字符串中每行开头的任何水平空白字符 (1 个答案)
正则表达式:表达式位于行首 OR NOT (2 个答案)
7 小时前关闭。

我需要在 php 8 中检查配置文件中某些参数是否未注释,包括“;”的情况 符号可以带有空格:

#       other settings you may need to change.
  ;  server-id        =   1
log_bin                 = /var/log/mysql/mysql-bin.log

用正则表达式

[\s]*[^;][\s]*server-id[\s]*=[\s]*(.\d)

当“;”之前有空格时,会得到错误的结果 符号,当行被视为注释时:

https://regex101.com/r/n259oJ/1

我尝试在行的开头使用 \A,但失败了。

如何检查“;”之前没有空格 在线上 ?

  • 1 个回答
  • 47 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve