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

Polar_Bear's avatar

How to render limited Filament Datatables to Guest Users?

Greetings, Gang, Filament NOOB here. Am trying to determine best way to render read-only datatables views on latest Laravel 10 TALL stack with Jetstream and FilamentPHP plugin for guest users. I aim to leverage Filament's read only features while keeping the excellent sortable, searchable, etc functionality in an SEO friendly way for unathenticated guests and searchbots to use through the landing page and a public web interfaces.

I would like to preserve the CRUD functionality to authenticated users with proper rules and permissions (super admin or multitenency, etc) either at the /admin/ routes or with a subdomain.

I am basically asking for a best practice (Filament V2,) for scaffolding the routes to facilitate guest use while allowing for admin use later and avoiding too much duplication and the need for frequent "canonical" cross referrals.

Thanks in advance

0 likes
2 replies
LaryAI's avatar
Level 58

One possible solution is to create a separate controller and view for the read-only datatable that is accessible to guest users. This controller would use the Filament DataTable class to generate the table data and pass it to the view. The view would then render the table using the Filament Blade components.

Here's an example of what the controller and view might look like:

// app/Http/Controllers/GuestController.php

use Filament\Tables\DataTable;

class GuestController extends Controller
{
    public function index()
    {
        $table = DataTable::make(new MyDataTable())
            ->paginate(10);

        return view('guest.index', [
            'table' => $table,
        ]);
    }
}
<!-- resources/views/guest/index.blade.php -->

<x-filament::app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Guest Dashboard') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
                <x-filament::table :table="$table" />
            </div>
        </div>
    </div>
</x-filament::app-layout>

In this example, MyDataTable is a custom Filament DataTable class that defines the columns and data for the table. The paginate method is used to limit the number of rows displayed on each page.

To restrict access to this controller to guest users, you can use Laravel's built-in middleware:

// app/Http/Controllers/GuestController.php

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

class GuestController extends Controller
{
    public function __construct()
    {
        $this->middleware(function (Request $request, $next) {
            if (Auth::check()) {
                return redirect('/dashboard');
            }

            return $next($request);
        });
    }

    // ...
}

This middleware checks if the user is authenticated and redirects them to the dashboard if they are. Otherwise, it allows the request to continue to the controller action.

Finally, to avoid duplication of routes and views, you can use Laravel's route prefixing feature to group the guest routes under a common prefix:

// routes/web.php

use App\Http\Controllers\GuestController;

Route::prefix('guest')->group(function () {
    Route::get('/', [GuestController::class, 'index'])->name('guest.index');
    // add more guest routes here
});

// regular authenticated routes go here

This groups all the guest routes under the /guest prefix, so you can access the datatable at /guest instead of creating a separate subdomain or duplicating the routes and views.

Polar_Bear's avatar

Thanks, Larry. Your Quickdraw AI brain is fast! I'll monitor for other ideas while tinkering with yours.

Please or to participate in this conversation.