我正在尝试使用jquery数据表从mysql数据库输出一些数据。

这是我的路线:

Route::get('datatables', ['as' => 'HomeController', 'uses' => 'HomeController@getIndex']);Route::get('payments-data', ['as' => 'HomeControllerPaymentsData', 'uses' => 'HomeController@Payments']);

我的控制器HomeController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Carbon\Carbon;

class HomeController extends Controller
{


    public function getIndex()
    {
        return view('payments');
    }

    /**
     * Process datatables ajax request.
     *
     * @return \Illuminate\Http\JsonResponse
     */
    public function Payments()
    {
        return Datatables::of(DB::table('Payment'))->make(true);
    }


这是我的刀片/视图:

@extends('layouts.master')
@section('content')

            <div class="table-responsive">
                <table class="table table-hover" id="payments-table">


                    <thead>
                    <tr>
                        <th>Id</th>
                        <th>Name</th>
                        <th>Amount</th>
                    </tr>
                    </thead>
                </table>
            </div>
            </div>
            @push('scripts')
            <script>
                $(function() {
                    $('#payments-table').DataTable({
                        processing: true,
                        serverSide: true,
                        scrollX: true,
                        ajax: '{!! route('payments-data') !!}',
                        columns: [
                            { data: 'id', name: 'id' },
                            { data: 'name', name: 'name' },
                            { data: 'amount', name: 'amount' },
                        ]
                    });
                });
            </script>
           @endpush
           @endsection


但是,当我尝试运行路线/datatables时,我得到了路线[payments-data] not defined. (View: /home/bob/Desktop/dibon/resources/views/payments.blade.php)这可能是做错了什么?任何人。

最佳答案

使用{!! route('HomeControllerPaymentsData') !!}中定义的Route::get('payments-data', ['as' => 'HomeControllerPaymentsData', 'uses' => 'HomeController@Payments']);

关于php - 在laravel 5.3中未定义的路线[付款数据],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39946578/

10-13 01:06