【问题标题】:In laravel livewire, I want to get the user only if it's value changed from specific value to another specific value在 laravel livewire 中,只有当它的值从特定值更改为另一个特定值时,我才想获取用户
【发布时间】:2021-10-06 05:58:09
【问题描述】:

如果g10_eng_unwh 等于1,这是我获取用户的代码。

public function purchased(User $user)
{
     if ($user->g10_eng_unwh == 1) {
         $token = "g10_eng_unwh";
     }
     if ($user->g7_eng_unwh == 1) {
         $token = "g7_eng_unwh";
     }
     $time = Carbon::now()->format('Y-m-d');
     dd($user->email, $time, $token);
}

相反,我只想在 g10_eng_unwh 值从 0 变为 1 时获取用户。 有什么办法吗?

【问题讨论】:

  • 但您想通过查询或模型更新让用户监听该事件?

标签: laravel laravel-livewire


【解决方案1】:

您需要在开始时获取过去的值,以便您可以应用条件,它必须存储在某个地方。您很可能需要创建g10_eng_unwh_old 或类似的东西。我假设g10_eng_unwh 是数据库中的一个列,在这种情况下创建g10_eng_unwh_old 并将旧值存储在其中。

在这种情况下,您甚至可以根据要求获得它。例如

DB::query()
 ->where('g10_eng_unwh', 1)
 ->where('g10_eng_unwh_old', 0)
 ->get();

【讨论】:

  • 非常感谢。我按照你说的解决了。
猜你喜欢
  • 2021-08-10
  • 1970-01-01
  • 1970-01-01
  • 2019-10-13
  • 2020-07-26
  • 2016-08-04
  • 1970-01-01
  • 1970-01-01
  • 2021-11-21
相关资源
最近更新 更多