我想name用 AlpineJS 在循环中设置隐藏输入字段的属性。我试过了,x-bind:name但这不起作用。
我认为这不起作用,因为x-model如何添加待办事项:
<input x-model="todoText" type="text">
<button x-on:click.prevent="addTodo('new', todoText)">
Add
</button>
Run Code Online (Sandbox Code Playgroud)
我怎样才能使下面的工作,以便todos数组中的索引键设置为该todoSingle.id值?
<template x-for="todoSingle in todoArray" :key="todoSingle.id">
<input type="hidden" name="todos[todoSingle.id][id]" x-model="todoSingle.id">
<input type="hidden" name="todos[todoSingle.id][type]" x-model="todoSingle.type">
<input type="hidden" name="todos[todoSingle.id][description]" x-model="todoSingle.description">
</template>
Run Code Online (Sandbox Code Playgroud)
更新
代码笔在这里。如果添加待办事项,然后返回输入字段并键入,您将看到在每个键上都添加了相同的待办事项。
我有一个 Livewire 组件,它是一个产品过滤器。这些查询都工作正常,但有时它会创建无限循环的请求。
您可以在下面的 GIF 中看到发生的情况,它是 Laravel 调试栏的捕获。我单击一些过滤器,然后突然进入此请求循环。
我专门wire:loading.attr="disabled"在视图中使用过滤器,这样在请求仍在处理时就无法选择过滤器。
我的代码和一些背景:
带电组件
use App\Models\Product;
use App\Models\Brand;
use App\Models\Color;
class SearchProducts extends Component
{
public ?array $brand = [];
public ?array $color = [];
protected $queryString = ['brand', 'color'];
public function render()
{
$products = Product::query();
$products = $products->with('brand');
$products = $products->with('colors');
$products = $this->filterBrands($products);
$products = $this->filterColors($products);
$products = $products->paginate(24);
return view('livewire.search-products', [
'all_brands' => Brand::where('status', 'active')->get(),
'all_colors' => Color::where('status', 'active')->get(),
])->extends('app');
}
public function filterBrands($query)
{
$queryFilterBrand = …Run Code Online (Sandbox Code Playgroud) 如果我这样做:
$image = '/storage/images/image.jpg';
list($width, $height) = getimagesize($image);
Run Code Online (Sandbox Code Playgroud)
我明白了:getimagesize(/storage/images/image.jpg): failed to open stream: No such file or directory这是有道理的,因为它没有完整的 URL。
但如果我这样做:
$image = url('/').'/storage/images/image.jpg'; // Added url('/')
list($width, $height) = getimagesize($image);
Run Code Online (Sandbox Code Playgroud)
页面永远停留在加载状态...
一些附加信息
更新
由于看起来服务器崩溃了,我以为不会有错误日志,但有:
getimagesize(http://127.0.0.1:8000/storage/images/image.jpg): failed to open stream: HTTP request failed! {"exception":"[object] (ErrorException(code: 0): getimagesize(http://127.0.0.1:8000/storage/images/image.jpg): failed to open stream: HTTP request failed! at /Users/username/Documents/dev/test/app/Http/Controllers/PagesController.php:50)
Run Code Online (Sandbox Code Playgroud)
PagesController 中的第 50 行是
list($width, $height) = getimagesize($image);
Run Code Online (Sandbox Code Playgroud)
并如图所示$image = url('/').'/storage/images/image.jpg';
如果我在浏览器中输入 URL,http://127.0.0.1:8000/storage/images/image.jpg …
在AlpineJS 文档中有这个例子:
<div x-data="dropdown()">
<button x-on:click="open()">Open</button>
<div x-show="isOpen()" x-on:click.away="close()">
// Dropdown
</div>
</div>
<script>
function dropdown() {
return {
show: false,
open() { this.show = true },
close() { this.show = false },
isOpen() { return this.show === true },
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
现在我想做的是在其中<script>有另一个调用的函数close(),所以类似:
function aNewFunction()
{
close();
}
Run Code Online (Sandbox Code Playgroud) 我有一个 PHP 数组,我将其保存到 MySQL 中的 TEXT 列中,并json_encode($array)在保存到数据库之前使用它。
现在我想在 HTML 页面(Laravel 中的 Blade 模板)中漂亮地打印它,现在它显示为一长行文本。
我想我可以将它保存为一个数组,然后json_encode()在 Blade 模板中显示它时使用。但我想知道是否可以使用 将其保存到数据库json_encode(),并在 Blade 模板中以 JSON 格式漂亮地显示它。
在 Laravel 工厂中我有:
'created_at' => now()->subDays(mt_rand(1,90))->subHours(mt_rand(1,23))->toDateTimeString()
Run Code Online (Sandbox Code Playgroud)
这以前工作得很好,我认为它是在 Laravel 7.2 上。我所说的“工作正常”是指我运行它来插入 10.000 行或更多行,并且从未失败。更新到 7.10.3 后,我现在收到以下错误:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2020-03-29 02:10:11' for column 'created_at'
Run Code Online (Sandbox Code Playgroud)
它实际上在失败之前插入了几百行,因此它似乎是失败的特定日期或时间。在实际插入的行中,有些行的日期也为 2020-03-29,有些行的时间为 02:10:11,所以我不知道为什么这是“无效格式”。