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

RaduCruceana's avatar

How to specify the database name in Jajra/ Datatables

I'm using Laravel 5 with Jajra/Datatables

The project use 3 databases, one is MySQL and 2 are commercial SQL databases.

The SQL databases have the tables with exactly same names.

If I want to display a table from MySql database I use in controller:

return  Datatables::of(DB::table('coeficientVR_VanzariNoi')
        ->get(['id','marca','model','capacitate','combustibil', 'caroserie', 'altaClasaSchimb', 'coeficient',
              ]))->make(true);

and it's working great!

How to specify a table from one of the the SQL databases?

I have models associated to them, and models have the connection specified.

Example for one of table which is named "version":

class version_Jato extends Model
{
    //
    protected $connection = 'sqlJato';
    protected $table = 'version';
    protected $primaryKey = 'vehicle_id';

....

So I need to specify the SQL database but I don't know how.

Thank you for your time!

0 likes
4 replies
RaduCruceana's avatar

@Cronix

Thank you sir, i already did that.

When i use query builder I already use it like that:

$auto = DB::connection('sqlJato')->table('version as v')-> 

...

My question is specific to Yajra\DataTables facade.

How do I specify the connection in

return  Datatables::of(DB::table('oferte as o')
...
Cronix's avatar

You're not specifying the connection() to use in your 2nd code block with Datatables like you are in your first.

RaduCruceana's avatar

@cronix

Yes, because Yajra/Datatables facade does not have connection() or at least I don't know how to use it.

If I try:

return  Datatables::connection('sqlJato')->of(DB::table('coeficientVR_VanzariNoi')
...

I get an Datatables error.

Please or to participate in this conversation.