我正在尝试了解 Laravel 8 的新功能upsert。
这是我的示例表:
flights
id (primary key and auto Inc)
departure
destination
price
Run Code Online (Sandbox Code Playgroud)
在我的代码中:
App\Models\Flight::upsert([
['departure' => 'Oakland', 'destination' => 'San Diego', 'price' => 99],
['departure' => 'Chicago', 'destination' => 'New York', 'price' => 150]
], ['departure', 'destination']);
Run Code Online (Sandbox Code Playgroud)
这是 Laravel 文档中的示例表,它有一个键 id。
departure如果 和都匹配,我想更新记录destination,但这些字段不是唯一的。
每次我运行代码时,它都会插入一条新记录但不会更新。如何开始upsert工作?
我是否需要使 和 都departure变得destination独特,或者在不使它们变得独特的情况下它会起作用吗?
另外,如果我需要使这两个字段都唯一,那么我该如何在迁移中做到这一点?
我有3个mysql表(order,camp,user)作为下面的值,
order_table
ID camp_id orderDate message
1 1 2015-01-01 ok
2 1 2015-02-01 ok
3 2 2015-03-01 not ok
4 3 2015-01-01 not ok
5 1 2015-04-01 not ok
6 2 2015-01-01 ok
7 3 2015-07-01 not ok
camp_table
camp_id camp_uid camp name
1 10 first camp
2 11 second camp
3 12 third camp
4 10 forth camp
user_table
uid uname
10 abc
11 xyz
12 wrt
Run Code Online (Sandbox Code Playgroud)
我希望结果如下
uname,camp name,message
Run Code Online (Sandbox Code Playgroud)
通过orderDate从order_table获取今日订单的每个用户的最后2条记录
我想加入这些表有UNAME从USER_TABLE和 …
我是 LiveWire 新手,尝试使用 Laravel 、 jetstream 和 livewire 构建简单的应用程序
我的应用程序从数据库获取数据并显示在带有分页的表中。一切工作正常,但问题是当我单击任何页面时,我得到 URI '?page=2'
我不想在 Url 中看到这个 URI 我的刀片也很简单,如下所示
<x-app-layout>
<x-slot name="header">
</x-slot>
<div class="py-2">
<div class="mx-auto sm:px-2 lg:px-2">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
<div class="flex flex-wrap">
<livewire:item />
</div>
</div>
</div>
</div>
</x-app-layout>
Run Code Online (Sandbox Code Playgroud)
和火线:项目
<table class="table-auto w-full">
<thead>
<tr>
<th class="px-4 py-2">
<div class="flex items-center">
<button>Image</button>
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('sku')">SKU</button>
<x-sort-icon sortField="sku" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('title')">Title</button> …Run Code Online (Sandbox Code Playgroud) 我想要有干净的 URL,并且我的表工作正常,直到我更新 Livewire,现在我的表正在添加查询字符串,如第 2 页中的 ?page=2
所有代码都和以前一样,搜索后我将其添加到 Livewire 控制器命名空间 App\Http\Livewire 中;
use Livewire\Component;
use Livewire\WithPagination;
class ContactsTable extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
protected $paginationQueryStringEnabled = false;
Run Code Online (Sandbox Code Playgroud)
但它仍然在 URL 中显示查询字符串,我该如何禁用它?
谢谢