scala
13
18
Laravel

fetch data from controller and display in table view

Posted 3 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.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.