Reputation: 4180
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
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