Livewire live/real time search | rea time search in laravel livewire | data filter in livewire

 

 Create livewire component 

Search.php

<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Student;
class Search extends Component
{
    public $searchdata;
    public function render()
    {
        if(is_null($this->searchdata)){
         $students=Student::all();
        }else{
            $students=Student::where('name','Like','%'.$this->searchdata.'%')->orWhere('content','Like','%'.$this->searchdata.'%')->get();
        }
       
       
        return view('livewire.search',compact('students'));
    }
}

livewire blade file 

livewire/search.blade.php

<div>
    <h2>Livewire Search</h2>
    <form>
        <input type="text"   wire:model="searchdata" placeholder="Enter key word">
    </form>
    <table class="table table-bordered table-hover">
        <thead>
            <tr>
                <th>#</th>
                <th>Name</th>
                <th>Content</th>
                <th>Action</th>

            </tr>
        </thead>
        <tbody>
            @foreach($students as $key=>$std)
            <tr>
                <td>{{++$key}}</td>
                <td>{{$std->name}}</td>
                <td>{{$std->content}}</td>
                <td>Edit| Delete</td>

            </tr>
            @endforeach
        </tbody>
       
    </table>
</div>

View blade file

studendt/search.blade.php

@extends('layouts.app')
@section('content')

<div class="container">
    @livewire('search')
</div>

@endsection


Route

Route::view('search','student.search');


বাসা ভাড়ার সহজ মাধ্যম

www.basabaribd.com

 

জব প্রস্তুতির সেরা প্লাটফরম

www.jiboneralo.com

No comments

Powered by Blogger.