dongluzhi5208 2016-10-09 17:42
浏览 37
已采纳

路线[payment-data]未在laravel 5.3中定义

I am trying to use jquery datatables to output some data from a mysql database.

Here is my route:

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

My controller 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);
    }

Here is my blade/view:

@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

However, when I try to run the route /datatables I get Route [payments-data] not defined. (View: /home/bob/Desktop/dibon/resources/views/payments.blade.php) What could be doing wrong? Anyone.

  • 写回答

1条回答 默认 最新

  • doutou7286 2016-10-09 17:45
    关注

    Use {!! route('HomeControllerPaymentsData') !!} as defined in Route::get('payments-data', ['as' => 'HomeControllerPaymentsData', 'uses' => 'HomeController@Payments']);.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大