小编Mad*_*sen的帖子

如果请求值为 null,Laravel 设置默认值

我正在尝试为 Laravel 迁移设置默认值。我正在使用 SQLite。

\n

当我尝试插入一条包含分配了默认值的字段的记录时,返回错误: SQL 错误或缺少数据库(表客户没有名为国家/地区的列)

\n

这是迁移脚本:

\n
php\nSchema::create(\'customers\', function (Blueprint $table) {\n            $table->id();\n            $table->string(\'name\');\n            $table->string(\'contact_person_first_name\');\n            $table->string(\'contact_person_name\');\n            $table->string(\'contact_person_email_address\');\n            $table->string(\'address\');\n            $table->string(\'zipCode\');\n            $table->string(\'city\');\n            $table->string(\'country\')->default("BELGI\xc3\x8b");\n            $table->string(\'vat_number\')->default("BE");\n            $table->timestamps();\n
Run Code Online (Sandbox Code Playgroud)\n

控制器:

\n
php\nSchema::create(\'customers\', function (Blueprint $table) {\n            $table->id();\n            $table->string(\'name\');\n            $table->string(\'contact_person_first_name\');\n            $table->string(\'contact_person_name\');\n            $table->string(\'contact_person_email_address\');\n            $table->string(\'address\');\n            $table->string(\'zipCode\');\n            $table->string(\'city\');\n            $table->string(\'country\')->default("BELGI\xc3\x8b");\n            $table->string(\'vat_number\')->default("BE");\n            $table->timestamps();\n
Run Code Online (Sandbox Code Playgroud)\n

请求:

\n
     * Store a newly created resource in storage.\n     *\n     * @param CreateCustomerRequest $request\n     * @return \\Illuminate\\Http\\RedirectResponse\n     */\n    public function store(CreateCustomerRequest $request)\n    {\n        Customer::create($request->validated());\n        return response()->redirectTo(\'/customers\');\n    }\n
Run Code Online (Sandbox Code Playgroud)\n

我要执行的 sql 脚本:\n在此输入图像描述

\n …

migration request default-value laravel

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

Laravel 模型项目设置碳项目但返回字符串

我在数据库模式中添加了一个日期时间:

$table->dateTime('send_at')->nullable();
Run Code Online (Sandbox Code Playgroud)

我已将属性设置为播种器中的 Carbon 实例:

$invoice->send_at = Carbon::now();
Run Code Online (Sandbox Code Playgroud)

当我尝试获取控制器内属性的类型时,它返回一个字符串:

dd(gettype($data['invoices'][0]->send_at));
Run Code Online (Sandbox Code Playgroud)

到底是怎么回事?我如何确定它是一个 Carbon 对象而不是一个字符串?

datetime types laravel php-carbon

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

Laravel 7:单元测试在 setUp() 中设置默认请求标头

我想在 setUp 方法中为测试中的所有请求设置标头,而不是单独对所有测试进行设置。

是否有捷径可寻?

所以例子:

$this->withHeaders([
            'Authorization' => 'Bearer ' . $response['data']['token'],
            'Accept' => 'application/json'
        ])
Run Code Online (Sandbox Code Playgroud)

到:

setUp(){
$this->setHeaders([
            'Authorization' => 'Bearer ' . $response['data']['token'],
            'Accept' => 'application/json'
        ]);
}
Run Code Online (Sandbox Code Playgroud)

testing global laravel laravel-7

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

如何使用tailwindcss更改悬停宽度

我正在尝试使用 Tailwind css 在悬停时使 div 更宽。这可能吗?如何?

我已经尝试了以下但没有奏效:

class="w-1/3 hover:w-3/5"
Run Code Online (Sandbox Code Playgroud)

css hover width tailwind-css

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

Tailwindcss group-hover not working on border color

When I hover over a navigation item, I want a span border color to be changed. The group-hover does nothing...

Is this just not implemented in Tailwindcss yet?

 <a class="group px-4 py-2 hover:bg-white
            hover:text-primary transition-colors duration-300
            rounded-sm"
     :href="route">
    <span class="pb-1 border-b border-white group-hover:border-black">
        <slot/>
    </span>
  </a>
Run Code Online (Sandbox Code Playgroud)

I obviously can do this by writing css like this, but tailwind should be able to do this, right?

a:hover span {
  border-color: black;
}
Run Code Online (Sandbox Code Playgroud)

css hover tailwind-css

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