Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tomasosho's avatar

Please Help: I am writing a search filtering app

When i filter my data i get "No data available in table", but without filter, i can view my data.

Code: https://github.com/Thomasosho/Custom-Search-filter-table-laravel-

Full Repo: https://github.com/Thomasosho/laravel-filter-table-through.git

0 likes
27 replies
jlrdw's avatar

Fix your code, some is in code blocks some is not, hard to read.

Also after fix, copy and paste here properly formatted if you want.

fylzero's avatar

@tomasosho

In your controller...

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class FurnitureController extends Controller {
    ...
fylzero's avatar

@tomasosho Also, in your view... you got a script tag AFTER your HTML tag... move that inside the closing body tag or it won't execute.

fylzero's avatar

@tomasosho Don't do this if (request()->ajax()) stuff. Make separate routes for ajax calls, if needed.

fylzero's avatar

@tomasosho Are you 100% sure the furniture table of your database is populated with data? Right database connection? All that?

fylzero's avatar

@tomasosho What is this line doing? return datatables()->of($data)->make(true);

Unless I am missing something... datatables() here isn't calling anything.

It looks like you are using a jQuery package for datatables and somehow trying to call a javascript function from PHP, maybe? idk. This stands out to me. Let me know what this code does, if datatables() here leads to a PHP function elsewhere.

jlrdw's avatar

@fylzero just fyi, you can edit a previous reply and add to it.

Usually just type Edit: on a new line and then skip one space.

1 like
fylzero's avatar

@jlrdw These are separate thoughts, I am separating them so I can come back and track them.

1 like
tomasosho's avatar

Thank You, It's on github now. Please help me check it out. I attached a photo of the result i'm getting. Thank You

fylzero's avatar

@tomasosho When you load the page, assuming you use Chrome dev tools, open your network tab... filter on XHR requests... are you getting a data response from the ajax request there?

Again, what does line 30 of your FurnitureController.php file do? Where is the datatables() function in your code?

return datatables()->of($data)->make(true);

Ok, so you're using https://github.com/yajra/laravel-datatables, right?

1 like
fylzero's avatar

@tomasosho Does your config\app.php contain?

'providers' => [
    ...,
    Yajra\DataTables\DataTablesServiceProvider::class,
]

'aliases' => [
    ...,
    'DataTables' => Yajra\DataTables\Facades\DataTables::class,
]
1 like
fylzero's avatar

@tomasosho Maybe try using php artisan tinker and running...

DB::table('furniture')->select('title', 'state', 'typeintervention', 'year', 'quality', 'totalcost', 'actualcost')->get();

Does that show any results?

1 like
tomasosho's avatar

I got a response on network filtering XHR requests.

datatables() it's to make new instance of the data table from the source.

fylzero's avatar

@tomasosho Any kind of errors in the Chrome console indicating there is a JavaScript issue?

1 like
tomasosho's avatar

I got results, and my providers and aliases are correctly filled in my config\app.php

fylzero's avatar

@tomasosho In your FurnitureController... if you comment out these lines, does your data table still work?

       $data = DB::table('furniture')
         ->select('title', 'state', 'typeintervention', 'year', 'quality', 'totalcost', 'actualcost')
         // ->where('state', $request->filter_state)
         // ->where('typeintervention', $request->filter_typeintervention)
         // ->where('year', $request->filter_year)
         // ->where('quality', $request->filter_quality)
         ->get();
      }

Thinking it should, since it would be the same as your no filter code... but bear with me.

If that does work... try uncommenting those lines and testing one by one to see if you can figure out if one or a couple of them are causing this to break. That should at least narrow things down.

1 like
tomasosho's avatar

I did, i tried them differently. same thing! I could give you remote control to my pc though!

fylzero's avatar

Give me a way to get in touch and I'll take a look at it for you... could also just post the entire repo and I could try it on my end, up to you.

1 like
fylzero's avatar

@tomasosho I emailed you, you can remove your email from the forum thread, if you want. Prevent spam from hitting you.

1 like
fylzero's avatar
fylzero
Best Answer
Level 67

@tomasosho I figured out the issue. Everything is wired correctly... your data has extra spaces in it... connect to your SQLite database using TablesPlus or whatever you use... look at your states... ' Imo State' is trying to match 'Imo State'... when you remove the tabs in front of your data... your filters work fine.

Yep, this is 110% the problem. Your code works fine. This is a badly formed data issue.

Also, ALL of your factories have a tab in front of the ' Imo State' reference

Please or to participate in this conversation.