小编Sho*_*obi的帖子

在Laravel 5.7中发布请求---错误 - 419抱歉,您的会话已过期

我安装了Laravel 5.7

在文件中添加了一个表单 \resources\views\welcome.blade.php

<form method="POST" action="/foo" >
    @csrf
    <input type="text" name="name"/><br/>
    <input type="submit" value="Add"/>
</form>
Run Code Online (Sandbox Code Playgroud)

添加到文件 \routes\web.php

Route::post('/foo', function () {
    echo 1;
    return;
});
Run Code Online (Sandbox Code Playgroud)

发送POST请求后:

419抱歉,您的会话已过期.请刷新并重试.

在版本5.6中没有这样的问题.

php laravel

50
推荐指数
13
解决办法
9万
查看次数

Laravel应用程序中Application键的意义是什么?

来自laravel docs

应用程序密钥安装Laravel后,您应该做的下一步是将应用程序密钥设置为随机字符串.如果通过作曲家或Laravel安装程序安装Laravel,这个密钥已经被设置为你的PHP工匠键:生成命令.

通常,此字符串应为32个字符长.密钥可以在.env环境文件中设置.如果您尚未将.env.example文件重命名为.env,则应立即执行此操作.如果未设置应用程序密钥,则您的用户会话和其他加密数据将不安全!

我对应用程序密钥的了解是:如果未设置应用程序密钥,通常我会得到一个例外.

  • 这个随机字符串如何帮助保护会话?
  • 此应用程序密钥的其他用途是什么?
  • 如果我在任何地方使用相同的应用程序密钥(如登台,生产等等),是否会降低应用程序的安全性?
  • 这个密钥的最佳实践是什么?

php laravel

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

如何在 mac 中从命令行启动 docker

我在 mac 上安装了 docker 桌面。所以为了启动docker,我打开应用,找到docker。然后我可以在顶栏看到一个泊坞窗图标。稍后我可以从命令行运行 docker 命令。

我的问题是如何从命令行启动 docker 本身?

谷歌搜索获取我如何从命令行启动容器的结果:|

macos docker

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

我如何暂时禁用 django 中的数据库完整性约束 - postgresql

我正在编写一个 Django 命令来为现有表做种,

我需要在播种前截断该表,但该表有外键约束。

因此,我在截断表时收到django.db.utils.IntegrityError

如何在 Django 中暂时关闭外键检查?

我看到了,SET FOREIGN KEY CHECK = 0但不知道把它们放在哪里:(

Django 命令类:

class Command(BaseCommand):
help = "Command to seed the aws regions"
regions = [
    {
        'name': 'Us East (N. Virginia)',
        'region': 'us-east-1',
    },
    {
        'name': 'US West (Oregon)',
        'region': 'us-west-2',
    },
    {
        'name': 'EU (Ireland)',
        'region': 'eu-west-1',
    },
]
def handle(self, *args, **options):
    self.stdout.write('seeding regions...')

    AwsRegions.objects.all().delete() # this is where i get errors

    for name, region in self.regions:
        self.stdout.write(region)
        AwsRegions.objects.create(name, region) …
Run Code Online (Sandbox Code Playgroud)

django postgresql

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

请求的数据库类型未知,Doctrine\DBAL\Platforms\MySQL57Platform 可能不支持。Symfony 4

我创建了一个新的 symfony4 项目。使用户实体使用php bin/console make:user,然后尝试迁移使用php bin/console make:migration。但随后弹出错误

在 AbstractPlatform.php 第 434 行中:

请求的数据库类型未知,Doctrine\DBAL\Platforms\MySQL57Platform 可能不支持。

奇怪的是 User 实体没有任何enum类型,而是有一个 json 角色列,我想这就是原因。

 /**
 * @ORM\Column(type="json")
 */
 private $roles = [];
Run Code Online (Sandbox Code Playgroud)

我已经看到了 laravel 类似问题的一些答案,但不知道如何在 symfony4 中修复它。

php symfony doctrine-orm

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

如何在Laravel中链接多个外键

在开发银行应用程序时,在我的Laravel模型中,我有一个称为事务处理的表。

在该表中,有一列名为to_id和from_id,这是发送钱的用户的ID(from_id)和接收钱的用户的id(to_id),该ID链接到我的User表,

这是CreateTransactionsTable迁移代码

    Schema::create('transactions', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('from_id')->unsigned();
        $table->foreign('from_id')->references('id')->on('users');
        $table->bigInteger('to_id')->unsigned();
        $table->foreign('to_id')->references('id')->on('users');
        $table->integer('Amount');
        $table->enum('TransactionType', ['Credit', 'Debit']);
        $table->enum('Status', ['Completed', 'Incomplete']);
        $table->timestamps();
    });
Run Code Online (Sandbox Code Playgroud)

这是CreateUserTable迁移文件的代码

Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');            
            $table->string('AccountNumber')->unique();
            $table->rememberToken();
        });
Run Code Online (Sandbox Code Playgroud)

这是事务模型的代码

class Transactions extends Model{
    public function users(){
        return $this->belongsTo('App\Users');
    }
}
Run Code Online (Sandbox Code Playgroud)

这是用户模型的代码

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable{
    use Notifiable;

    protected $fillable = [
        'name', 'email', 'password', 'Amount',
    ];

    public function transactions(){
        return $this->hasMany('App\Transactions');
    } …
Run Code Online (Sandbox Code Playgroud)

php laravel eloquent laravel-5

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

vuejs中如何获取组件编译后的html内容

我有一个像这样的组件<AgentCard :agent="agent" />,其中agent有一个具有诸如等属性的对象FirstName, LastName, Recent Orders......

现在我需要在 Google 地图信息框中显示此组件。该infoWindow.setContent()方法(显示弹出信息窗口的 Google Maps API)仅接受 HTML 字符串,因此我尝试手动渲染<AgentCard>,获取渲染组件的 HTML 内容,并将其传递给该setContent()方法。

我尝试过Vue.compile('<AgentCard :agent="agent" />').render(),但这不起作用。如何手动渲染 Vue 组件并获取其 HTML 内容?

javascript vue.js

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

Symfony 6 中的命名路由,控制器位于内部目录中

我将所有控制器移至/src/Web/Controller我的 Symfony 6 项目中,如下所示

\n
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Web\n\xe2\x94\x82   |    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Controller\n\xe2\x94\x82   |    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ....\n|   |\xe2\x94\x80\xe2\x94\x80 Kernel.php\n
Run Code Online (Sandbox Code Playgroud)\n

我的routes.yaml作相应修改

\n
\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 src\n\xe2\x94\x82   \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ...\n\xe2\x94\x82   \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 Web\n\xe2\x94\x82   |    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 Controller\n\xe2\x94\x82   |    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 ....\n|   |\xe2\x94\x80\xe2\x94\x80 Kernel.php\n
Run Code Online (Sandbox Code Playgroud)\n

现在的问题是我所有的路线都有一个前缀为的名称app_web。我想这是由于这种结构。

\n

$ php bin/console debug:router命令输出如下:

\n
...\n...\napp_web_post_index    GET|HEAD        ANY      ANY    /post/             \napp_web_post_create   GET|HEAD|POST   ANY      ANY    /post/create \n
Run Code Online (Sandbox Code Playgroud)\n

在这里我只想要名字post_indexHow do I摆脱这个前缀?

\n

php symfony symfony-routing symfony6

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

构造函数注入和依赖注入中的“注入”是什么意思

我已经阅读了依赖注入。然后来了

  • 构造函数注入,
  • 吸气剂注入
  • 二传手注射
  • 接口注入

它们与依赖注入有何不同或它们都相同?注射在这里是什么意思?只是将所需的对象/参数提供给类?像构造注入意味着将所需参数作为构造函数参数传递?还是我错过了什么?

dependency-injection terminology constructor-injection

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

TS2345:'number 类型的参数 | undefined' 不能分配给类型为 'number' 的参数

我正在尝试在打字稿中创建一个 chrome 扩展。

我有以下代码,我尝试从后台脚本向 contentscript 发送消息。

// background script 
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
   chrome.tabs.sendMessage(tabs[0].id, {action: "open_dialog_box"}, function(response) {
      console.log(response);
   });  
});
Run Code Online (Sandbox Code Playgroud)

但是打字稿给出了以下错误

ERROR in /Users/shobi/Projects/Chrome Extensions/src/js/background.ts(8,37)
      TS2345: Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
  Type 'undefined' is not assignable to type 'number'.
Run Code Online (Sandbox Code Playgroud)

我尝试使用 parseInt() 将 id 转换为整数,但仍然没有阻止错误。

google-chrome-extension typescript

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