如何根据输入从数据库中获取特定行,以添加到另一个数据库?Laravel / Livewire



当前代码显示错误"无法解析依赖项[参数#0 [$identity]]在类AppHttpLivewireUsers">

这段代码有望获取输入($identity),根据accountno或email搜索人事表,然后将其添加到users表,

我正在使用这些函数

public function personnelCheck($identity)
{        
$this->resetErrorBag();
$user = Personnel::where('AccountNumber', $identity)
->orWhere('OfficialEmail', $identity)->first();
$this->personnelExists = true;
}

public function saveUser() 
{
$pw = User::generatePassword();

User::create([
'accountno' => $user['AccountNumber'],
'email' => $user['OfficialEmail'],
'password' => $pw,
'password_changed_at' => Carbon::now()->toDateTimeString(),
'status' => 0
]);
$this->confirmingUserAdd = false;

}

我的前端是

<x-dialog-modal wire:model="confirmingUserAdd">
@if($personnelExists == false)
<x-slot name="title">
{{ __('Enter Personnel Detail to Add User') }} {{$identity}}
</x-slot>

<x-slot name="content">
<div class="col-span-6 sm:col-span-4 dark:text-white-800">
<x-label for="identity" value="{{ __('Personnel Account Number or Official Email') }}" />
<x-input id="identity" type="text" class="mt-1 block w-full" wire:model.defer="identity" />
<x-input-error for="identity" class="mt-2" />
</div>
</x-slot>
<x-slot name="footer">
<x-jet-secondary-button wire:click="$set('confirmingUserAdd', false)" wire:loading.attr="disabled">
{{ __('Cancel') }}
</x-jet-secondary-button>

<x-jet-danger-button class="ml-2" wire:click="personnelCheck({{$identity}})" wire:loading.attr="disabled">
{{ __('Add Personnel') }}
</x-jet-danger-button>
</x-slot>
@else
<x-slot name="title">
{{ __('Personnel Details') }}
</x-slot>

<x-slot name="content">
<div class="col-span-6 sm:col-span-4 mt-4 dark:text-white-800">
@if($personnelExists == true)
Personnel: {{ $user->LastName }}, {{ $user->FirstName }}</br>
Gender: {{ $user->GenderDesc }}</br>
Official Email: {{ $user->OfficialEmail }}</br>
@endif
</div>
</x-slot>
<x-slot name="footer">
<x-jet-secondary-button wire:click="$set('confirmingUserAdd', false)" wire:loading.attr="disabled">
{{ __('Cancel') }}
</x-jet-secondary-button>

<x-jet-danger-button class="ml-2" wire:click="saveUser()" wire:loading.attr="disabled">
{{ __('Add Personnel') }}
</x-jet-danger-button>
</x-slot>
@endif
</x-dialog-modal>
livewire显示了这个模式,在输入$identity之前,它将提示输入字段,之后它将显示人员的详细信息。

我尝试不将变量传递给personnelCheck函数,

public function personnelCheck()
{        
$this->resetErrorBag();
$user = Personnel::where('AccountNumber', $identity)
->orWhere('OfficialEmail', $identity)->first();
$this->personnelExists = true;
}

我认为它可能不需要被声明,因为表单已经设置了$identity变量,但无论我用personnelCheck做什么,laravel在错误页面上告诉我$identity被设置为null。我从来没有设置过$identity变量

非常感谢!

public function personnelCheck()
{        
$this->resetErrorBag();
$user = Personnel::where('AccountNumber', $this->identity)
->orWhere('OfficialEmail', $this->identity)->first();
$this->personnelExists = true;
}

$this->identity应该声明为类的公共变量

相关内容

  • 没有找到相关文章

最新更新