![](/img/trans.png)
[英]How do I add a row to mysql db via php using controlled statements and html form for user input?
[英]How do I fetch a specific row from a db based on input, to add to another db? Laravel/Livewire
当前代码显示错误“无法解析 class App\Http\Livewire\Users 中的依赖项 [参数 #0 [$identity]]”
这段代码希望获取输入($identity),根据accountno或email搜索人员表,然后将其添加到用户表中,
我正在使用这些功能
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 之前,它将提示该输入字段,然后将显示人员的详细信息。
我尝试不将变量传递给 personalCheck function,
public function personnelCheck()
{
$this->resetErrorBag();
$user = Personnel::where('AccountNumber', $identity)
->orWhere('OfficialEmail', $identity)->first();
$this->personnelExists = true;
}
我认为可能不需要声明它,因为表单已经设置了 $identity 变量,但无论我对 personalCheck 做什么,laravel 在错误页面上告诉我 $identity 设置为 null anw。 我从来没有设置 $identity 变量。
非常感谢!
public function personnelCheck()
{
$this->resetErrorBag();
$user = Personnel::where('AccountNumber', $this->identity)
->orWhere('OfficialEmail', $this->identity)->first();
$this->personnelExists = true;
}
$this->identity 应声明为 class 公共变量
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.