alexa

Refactor Query Builder in Laravel ?

Refactor Query Builder in Laravel ?

You can write a base function and pass tableName to it and execute certain action

 public function getData($tableName) {
  $query = DB::table($tableName)->where('text', 'like', '%string')->get();
  foreach ($query as $row) {
          ...
   }

  // return result;
}

$tables = ['table1', 'table2', 'table3'];
$queryResponse = [];

foreach($tables as $tableName) {
    $queryResponse[$tableName] =  $this->getData($tableName);
}

181 0
7

Write a Comments


* Be the first to Make Comment

GoodFirms Badge
GoodFirms Badge

Fix Your Meeting With Our SEO Consultants in India To Grow Your Business Online

Facebook
Twitter
LinkedIn
Instagram
Whatsapp
Call Now
Quick Inquiry