Besoin d'aide ?

Laravel 8 DataTable 404 error

Avatar de Gelal

Hi everyone,

Im a beginner with laravel and actually im trying to learn about ajax in laravel using Yajra datatable. So i followed a this tutorial on the topic but whatever I do, I still get a 404 error in my console.

That what I have in my web.php

Route::get('/students', [StudentController::class, 'index']);
Route::get('/students/list', [StudentController::class, 'getStudents'])->name('students.list');

My StudentController.php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Student;

use Yajra\DataTables\Facades\DataTables;

class StudentController extends Controller
    public function index(){
        return view('students.index');

    public function getStudents(Request $request){
        if ($request->ajax()) {

            $data = Student::all();

            return DataTables::of($data)->make(true);

My index.blade.php

<!DOCTYPE html>
<html lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name='csrf-token' content="{{ csrf_token() }}">

    <link rel="stylesheet" href="{{ URL::asset('bootstrap.css') }}">
    <link rel="stylesheet" href="{{ URL::asset('dataTables.bootstrap.min.css') }}">
    <link rel="stylesheet" href="{{ URL::asset('dataTables.bootstrap4.min.css') }}">

    <title>DataTables Undersatnding</title>
    <div class="container">
        <table class="table-bordered table" id="table">

    <script src="{{ URL::asset('jquery-3.6.0.min.js') }}"></script>
    <script src="{{ URL::asset('dataTables.bootstrap.min.js') }}"></script>
    <script src="{{ URL::asset('dataTables.bootstrap4.min.js') }}"></script>
    <script src="{{ URL::asset('jquery.dataTables.min.js') }}"></script>
    <script src="{{ URL::asset('bootstrap.min.js') }}"></script>
    <script src="{{ URL::asset('bootstrap.bundle.min.js') }}"></script>
    <script src="{{ URL::asset('custom.js') }}"></script>

The custom.js

$(function () {
        serverSide : true,
        ajax : "{{ route('students.list') }}",
        columns: [
            {data : 'DT_RowIndex', name : 'DT_RowIndex'},
            {data : 'name', name: 'name'},
            {data : 'email', name: 'email'},
            {data : 'pseudo', name: 'pseudo'},
            {data : 'phone', name: 'phone'},
            {data : 'dob', name: 'dob'},

When im trying to run this, only the table header appear and in the console I have a : Failed to load resource : the server responded with a status of 404 (Not Found)

Posté il y a 1 mois

Vous ne pouvez pas répondre à ce sujet.