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

grozavule's avatar

Bind Model to Existing Database Table

I'm working on a project that pulls data from an existing SQL Server database. The database drives an ERP application, so I have no control over the table names. How do I bind a model class to any of these tables?

Here is what I'm trying to do specifically: I have a table named VMFG.LOGINS, a model named VisualLogin, and a controller named VisualLoginsController. When the destroy method is called in the controller, I would like to delete the corresponding record in the LOGINS table.

Here is the catch. I have three database connections that I'm juggling in this project. How do I assign the model to a database connection and table?

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

So you will need to define your connections within config/database.php file, and then in each model, you can include this properties:

protected $connection = 'your_connection';
    
protected $table = 'table_name';
grozavule's avatar

Nakov, you're the man. Thanks for replying.

Please or to participate in this conversation.