bmm bmm - 1 month ago 23
jQuery Question

Route [payments-data] not defined in 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.

Answer

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