پوریا
11 ماه پیش توسط پوریا مطرح شد
1 پاسخ

ساخت سرچ ساده با لایو وایر در لاراول

سلام من چطوری میتونم یک سرچ ساده با لایووایر در لاراول بنویسم ؟


ثبت پرسش جدید
رایموند
تخصص : مختصص وردپرس - برنامه نویس لار...
@Raymond 11 ماه پیش مطرح شد
0

درود خوبی...
کنترلر لایو وایر:

public $search;
    protected $queryString = ['search'];
    public $readyToLoad = false;

    public function loadUser()
    {
        $this->readyToLoad = true;
    }

public function render()
    {
        $users = $this->readyToLoad ? User::where('name','LIKE',"%{$this->search}%")->
        orWhere('name','LIKE',"%{$this->search}%")->
        orWhere('username','LIKE',"%{$this->search}%")->
        orWhere('email','LIKE',"%{$this->search}%")->
        orWhere('mobile','LIKE',"%{$this->search}%")->
        orWhere('position','LIKE',"%{$this->search}%")->
        orWhere('id',$this->search)->latest()->paginate(15) : [];
        return view('livewire.support.users.index', compact('users'))->extends('layouts.app')
            ->section('content');
    }

سمت کاربر:

<div class="card" wire:init="loadUser">
       <div class="mb-3 col-4 float-end" style="margin-top: -25px;">
                <label for="search"></label>
                <input type="text" class="form-control" id="search" wire:model.debounce.1000="search" placeholder="جستجوی کاربران ...">
            </div>
</div>

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام