Kannan Ramamoorthy
Kannan Ramamoorthy

Reputation: 4180

Right way of getting specific columns in Eloquent model

In our app few of our Eloquent models need only a specific columns always. What is the right way to have my method? As of now there is a new method written which does,

DB::table('MyTable')->selectRaw('required_column_list')

I feel it is odd since the table name is hard-coded. What is the right way to do?

Upvotes: 0

Views: 44

Answers (1)

pars
pars

Reputation: 439

If you don't want to hard-code table name, so you have to hard code ModelName? Use model name with getTable function DB::table(YourModel::create()->getTable());

Upvotes: 1

Related Questions