I am trying to display data from database to table format. But only table is displayed but not the data. Please see the image.
Table is
ordered_books with attributes 'BookID', 'BilledNum','BilledDate', 'Qunatity', 'Price', 'Remarks'
My questions are ::
- Why is the data not populating in the table?
- How can I check whether the table data from database is retrieved in Controller $ordered_books variable?
view page code
<table id="showBooksIn" class="table table-bordered">
<thead>
<tr>
<th>BOOK ID</th>
<th>BILLED DATE</th>
<th>BILLED NUMBER</th>
<th>QUANTITY</th>
<th>PRICE</th>
<th>REMARKS</th>
</tr>
</thead>
@foreach($data as $row)
<tr>
<td>{{$row['BookID']}}</td>
<td>{{$row['BilledNum']}}</td>
<td>{{$row['BilledDate']}}</td>
<td>{{$row['Qunatity']}}</td>
<td>{{$row['Price']}}</td>
<td>{{$row['Remarks']}}</td>
</tr>
@endforeach
</table>
controller code
public function index()
{
return view('pages.booksin', $this->fetchData());
}
function fetchData()
{
$ordered_books = OrderedBook::all()->toArray();
return compact('ordered_books');
}
model code
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class OrderedBook extends Model
{
//
}
route code
Route::resource('/book','BookController');
Route::resource('/order','OrderedBookController');
Route::get('/order/data','OrderedBookController@fetchData')->name('data');
Please help!!!
url of image uploaded :: https://ibb.co/mCc5od