小编Cam*_*ilo的帖子

Chrome 关闭后,如何阻止某些扩展程序在后台运行?

关闭 Chrome 后,某些扩展程序会继续在后台运行(例如云端硬盘或环聊)。

在不禁用扩展程序的情况下,我可以控制哪些扩展程序在 Chrome 关闭后可以继续运行吗?

google-chrome

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

Laravel无法删除或更新父行:外键约束失败

由于某些原因,用户无法删除帖子,如果它已被喜欢,它之前正在工作,但当我链接帖子与喜欢我一直收到此错误,我甚至无法删除它在续集专业版,除非我删除相关的喜欢先发帖子.

错误

SQLSTATE [23000]:完整性约束违规:1451无法删除或更新父行:外键约束失败(eliapi8.likes,CONSTRAINT likes_post_id_foreignFOREIGN KEY(post_id)REFERENCES posts(id))(SQL:delete from postswhere id= 149)

Mac上的续集专业版

也许这是我的架构?

帖子架构

Schema::create('posts', function (Blueprint $table) {
    $table->increments('id');
    $table->string('title');
    $table->text('body');
    $table->integer('user_id')->unsigned();
    $table->foreign('user_id')->references('id')->on('users');
    $table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)

喜欢Schema

Schema::create('likes', function (Blueprint $table) {
    $table->increments('id');
    $table->integer('post_id')->unsigned();
    $table->integer('user_id')->unsigned();
    $table->foreign('post_id')->references('id')->on('posts');
    $table->foreign('user_id')->references('id')->on('users');
    $table->softDeletes();
    $table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)

我喜欢和不喜欢的帖子,但用户无法删除已被喜欢的帖子.

PostController.php

public function destroy(Post $post){

    $this->authorize('delete', $post);
    $postl =  Post::with('likes')->whereId($post)->delete();

    if ($post->delete()) {
        if($postl){
             return response()->json(['message' => 'deleted']);
        }  
    };

    return response()->json(['error' => 'something went wrong'], 400);
}
Run Code Online (Sandbox Code Playgroud)

mysql laravel

10
推荐指数
2
解决办法
3万
查看次数

在 Next.js 中导入 ES 模块 ERR_REQUIRE_ESM

ky在 Next.js 项目中尝试使用时遇到了这个错误:

错误 [ERR_REQUIRE_ESM]:必须使用导入来加载 ES 模块:/foo/node_modules/ky/index.js

我认为问题在于 Webpack(或 Babel)正在将所有imports转换为require()s 但它ky是一个纯 ES 模块

ky在使用它之前通过动态导入让它工作,但它既不优雅也不高效。

const handleFormSubmit = async (event) => {
  const ky = (await import("ky")).default;

  const response = await ky
    .get('http://localhost/api/foo')
    .json();
};
Run Code Online (Sandbox Code Playgroud)

有什么建议?

javascript webpack babeljs es6-modules next.js

10
推荐指数
2
解决办法
2928
查看次数

从每个对话中获取最后一条消息

我之前曾经问过类似的问题,但是没有一个问题具有相同的条件,他们的答案对于这种情况不起作用.

包含消息的表如下所示:

id | owner_id | recipient_id | content      | created
 1 |        1 |            2 | Hello        | 2015-12-08 20:00
 2 |        2 |            1 | Hey          | 2015-12-08 20:10
 3 |        3 |            1 | You there?   | 2015-12-08 21:00
 4 |        1 |            3 | Yes          | 2015-12-08 21:15
 5 |        4 |            1 | Hey buddy    | 2015-12-08 22:00
Run Code Online (Sandbox Code Playgroud)

让我们说我查询用户ID 1的对话,预期结果是:

id | owner_id | recipient_id | content      | created
 5 |        4 |            1 | …
Run Code Online (Sandbox Code Playgroud)

mysql sql database relational-database

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

Laravel Homestead流浪了很多次

我正在关注在Homestead上运行Laravel 5.1的官方指南.

但是,当我尝试vagrant up它时,它会挂起homestead-7: SSH auth method: private key并最终超时消息:

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.
Run Code Online (Sandbox Code Playgroud)

我的SSH密钥是使用生成的ssh-keygen -t rsa -C "you@homestead".

无法访问机器vagrant ssh,它输出ssh_exchange_identification: read: Connection reset by peer.

尝试vagrant destroy并删除 …

ssh vagrant laravel homestead laravel-5.1

9
推荐指数
2
解决办法
6532
查看次数

将 Lodash debounce 与 React useCallback 用于输入 onChange 事件

onChange当用户在输入字段中键入内容时,我试图消除事件的反跳。

我正在引用这些线程:

我有以下代码片段,我尝试复制上面线程中提供的解决方案:

const handler = useCallback(debounce(setSearchQuery(value), 500), []);

useEffect(() => {
  document.addEventListener('keydown', handleDocumentKeyDown);
  handler(value);
  return () => document.removeEventListener('keydown', handleDocumentKeyDown);
}, [isOpen, handleDocumentKeyDown, handler, value]);

// ...

const handleChange = (event) => {
  setValue(event.target.value);
};
Run Code Online (Sandbox Code Playgroud)

错误:

未捕获的类型错误:处理程序不是函数

当用户在输入字段中键入内容时,setSerachQuery()如何消除反跳?500ms

javascript lodash reactjs react-hooks

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

如何确定弹出页面是否打开?

我正在开发Chrome扩展程序,我正在寻找如何(从后台页面)查看弹出页面是否打开.我查看了消息传递,但我不确定这是否会帮助我或者是否有更简单的方法.

谢谢!

javascript google-chrome-extension

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

ReferenceError:Next.js 中未定义 FileReader

我正在尝试使用该/app文件夹的 Next.js 13 的新功能,但在处理输入表单的简单客户端组件中,我尝试使用FileReader但在浏览时收到错误。

这是代码的摘要:

"use client";
import React, { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import useStore from "../app/store";

export default function FileUploader() {
  const [files, setFiles] = useState([]);
  const router = useRouter();
  const addFile = useStore((state) => state.addFile);

  const fileReader = new FileReader();

  const onFileSelect = (event) => {
    event.preventDefault();
    setFiles(event.target.files);
    console.log(event.target.files);
  };

  useEffect(() => {
    if (files[0] == null) return;
    let FileToString = fileReader.readAsText(files[0]); // get error at …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs next.js

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

具有固定参数值的路径的别名

我有这条路线:

Route::get('/MyModel/{id}', 'MyController@show');
Run Code Online (Sandbox Code Playgroud)

该方法show()接受一个被调用的参数id,我想设置一个别名,/MyModel/1以便它可以访问/MyCustomURL.

我已经尝试过几种组合,比如:

Route::get('/MyCustomURL', ['uses' => 'MyController@show', 'id' => 1]);
Run Code Online (Sandbox Code Playgroud)

但我不断错过方法所需的参数错误show().

在Laravel有没有一个干净的方法来实现这一目标?

php laravel laravel-routing laravel-5

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

如果使用use导入类,是否应该在PHPDoc中使用FQN?

假设我有一个UserController课程,并且正在使用导入该App\User课程use。在内部,有一种show()方法可以接收的实例User

namespace App\Http\Controllers;

use App\User;

class UserController extends Controller
{
    /**
     * Show user info
     * 
     * @param  User $user
     * @return Illuminate\Http\JsonResponse
     */
    public function show(User $user)
    {
        // Do something...
    }
}
Run Code Online (Sandbox Code Playgroud)

User即使我使用导入类,还是建议在PHPDoc中添加的完全限定名称use吗?

php phpdoc

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