Star

Join tables

Use plain SQL with any number of joins

There is no need for extra configuration because the library runs the SQL query you supply.
The library uses table column aliases as DataTables column names.
IDTrack NameAlbumMediaTypeUnitPriceMillisecondsBytes
Loading…
<?php
use Ozdemir\Datatables\Datatables;
use Ozdemir\Datatables\DB\SQLite;

Route::get('/ajax/join-tables', function () {
    $path = dirname(__DIR__).'/database/Chinook_Sqlite_AutoIncrementPKs.sqlite';

    $dt = new Datatables(new SQLite($path));
    $dt->query('Select TrackId, Track.Name, Title as Album, MediaType.Name as MediaType,
                UnitPrice, Milliseconds, Bytes
                FROM Track
                JOIN Album ON Album.AlbumId = Track.AlbumId
                JOIN MediaType ON MediaType.MediaTypeId = Track.MediaTypeId');

    return $dt->generate();
});