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

y53ybaqx  于 2022-11-18  发布在  其他
关注(0)|答案(1)|浏览(111)

当前代码显示错误“无法解析类App\Http\Livewire\Users中的依赖项[参数#0 [ $identity ]]”
这段代码很有希望获取输入($identity),根据accountno或email搜索personnel表,然后将其添加到users表,
im使用这些函数

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变量。
多谢了!

eoigrqb6

eoigrqb61#

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

        $this->personnelExists = true;
    }

$this-〉标识应声明为类公共变量

相关问题