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

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

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型