scala
63
18
Laravel

fetch data from controller and display in table view

Posted 6 months ago by scala

I am trying to display the fetched data in table but getting errors. showing error as

ErrorException (E_ERROR)
Undefined variable: devotee (View: C:\xampp\htdocs\laravel\lsapp\resources\views\pages\devoteeSearch.blade.php)

My table

//devoteeSearch.blade.php
<table id="books" class="table table-bordered gridview">
        <thead>
            <tr>
                <th>BOOK ID</th>
                <th>BOOK NAME</th>
                <th>UNIT PRICE</th>
                <th>EDIT</th>
            </tr>
        </thead> 
        <tbody>
            @foreach($devotee as $data)
             <tr>
                 <td> {{$data['NAME']}} </td>
                 <td> {{$data['CONTACT']}} </td>
                 <td> {{$data['TEMP_ADDRESS']}} </td>
            </tr>
            @endforeach
        </tbody>          
</table>

controller block

public function search(Request $request)
{
    $UserName = $request->input('devoteeName');
    
    if($UserName != ""){
        $devotee = Devotee::where ( 'NAME', 'LIKE', '%' . $UserName . '%' )->get (['id','NAME','CONTACT','TEMP_ADDRESS']);
        if (count ( $devotee ) > 0)
        {
            return view ( 'pages.devoteeSearch' ,compact('devotee'));
        }                
        else
        {
            return view ( 'pages.devoteeSearch' )->with('alert-danger', 'Sorry No details found'); 
        }
            
    }
}

route page

Route::get('/devoteeSearch','[email protected]');
Route::post('/devoteeSearch','[email protected]');

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.