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

<table id="books" class="table table-bordered gridview">
                <th>BOOK ID</th>
                <th>BOOK NAME</th>
                <th>UNIT PRICE</th>
            @foreach($devotee as $data)
                 <td> {{$data['NAME']}} </td>
                 <td> {{$data['CONTACT']}} </td>
                 <td> {{$data['TEMP_ADDRESS']}} </td>

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'));
            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


Reply to

Use Markdown with GitHub-flavored code blocks.