数据表和插入表单在一起时的路由方法

时间:2018-07-18 10:36:50

标签: php laravel laravel-5 routes

我正在尝试以表单形式实现数据表。我有一个表格,下面需要显示数据库中存在的所有数据。我正在关注教程https://www.youtube.com/watch?v=zwz_cMvASCo

我无法为DataTable编写Route方法,我所遵循的教程只显示了DataTable,但是这里有一个显示DataTable的表格。请参阅附件。

// OrderedBookController controller class

use App\OrderedBook;
use Datatables;

public function index()
    {
        return view('pages.booksin');
    }

function fetchData()
{
    $ordered_books = OrderedBook::select('BookID', 'BilledNum','BilledDate', 'Qunatity', 'Price', 'Remarks');
    return Datatables::of($ordered_books)->make(true); //return an instance of the class or interface you request
}

//OrderedBook model class
class OrderedBook extends Model
{
    //
}

我不知道如何编写路由方法来显示数据。 我的web.php

Route::resource('/order','OrderedBookController');

我的视图页面在resources\views\pages\booksin.blade.php

查看页面示例代码

<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>
        </table>

<script type="text/javascript">
        $(document).ready(function(){
        $('#showBooksIn').DataTable({
            "processing":true,
            "serverside":true,
            "columns":[
                {"data": "BookID"},
                {"data": "BilledNum"},
                {"data": "BilledDate"},
                {"data": "Qunatity"},
                {"data": "Price"},
                {"data": "Remarks"},


            ]
        });
    });
</script>

enter image description here

1 个答案:

答案 0 :(得分:0)

public function index()
{
  return view('pages.booksin', $this->fetchData());
}

尝试一下。