我有一个社交网络,希望在会话中存储用户的兴趣爱好,因为有许多子页面需要这些数据,我希望避免在每个页面上查询数据库。但是,您似乎只能在Livewire中将闪存数据保存在会话中。
通常用于在会话中保存数据的Laravel $request->session()->put(...)功能在Livewire中似乎不起作用。那么,我如何在会话中长期保存数据,或者是否有其他选项或功能?
发布于 2022-02-28 11:57:02
所以,我自己找出了答案。
实际上,您可以只使用session()->put('key', 'value')。
我不知道为什么这还没有正式记录下来。也许这对你也有帮助。
发布于 2022-06-01 05:32:12
在带电组件中:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Producto;
use Livewire\WithPagination;
class Filtro extends Component
{
public $marca;
public function render()
{
if(isset($this->marca)){ session()->put('marca', $this->marca);}
$productos = Producto::where('deleted',0)
->where('marca','like', '%'.session('marca').'%')
->orderBy('id')
->paginate(20) ;
return view('livewire.filtro', [
'productos' => $productos
]);
}
}在视图刀片:
<div class="filter__location">
<input type="text" class="form-control" placeholder="Marca" wire:model.debounce.1000ms="marca"
@if (session('marca'))
value="{{ session('marca') }}"
@endif
/>
</div>https://stackoverflow.com/questions/71294493
复制相似问题