clean up clean up every body does their hair

3 years ago

realtydev

Code

$counties = new CountyListDefault(); // uscounties table
$counties = $counties
  ->getCounties('al')
  ->get()
  ->toArray();
//dd($counties);die;
$options = [
  'keys' => ['county'],
  'threshold' => 0.34,
  'shouldSort' => true,
  'includeScore' => true,
];

$arrayBlackList = array(
  'other',
  'out of area',
  'other state',
  'other california',
  'usa',
  'us',
  'state of california',
  'outside of florida',
  'foreign country',
  'counties',
  'al counties',
);

$fuse = new \Fuse\Fuse($counties, $options);

function GetAlexProps($state)
{
  DB::connection()
    ->getPdo()
    ->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
  $properties = new Property();
  return $properties
    ::select('id', 'countyOrParish')
    ->skip(180)
    ->take(15)
    ->where(['state' => $state])
    ->whereNotNull('countyOrParish')
    ->cursor();
}

$counties = [];
foreach (GetAlexProps('ga') as $prop) {
  $county = str_ireplace(
    ' county',
    '',
    preg_replace('/[0-9]+/', '', strtolower($prop->countyOrParish))
  );
  if (
    !array_key_exists($county, $counties) &&
    !is_numeric($county) &&
    !in_array(strtolower($prop->countyOrParish), $arrayBlackList)
  ) {
    $counties[] = array(
      'id' => $prop->id,
      'county_default' => $county,
      'county_clean' => $fuse->search(strtolower($prop->countyOrParish))
        ? strtolower(
          $fuse->search(strtolower($prop->countyOrParish))[0]['item']['county']
        )
        : '',
    );

    continue;
  }
}

dd($counties);

Output

[!] Aliasing 'CountyListDefault' to 'App\Models\CountyListDefault' for this Tinker session.
[!] Aliasing 'Property' to 'App\Models\Property' for this Tinker session.
Illuminate/Database/QueryException with message 'SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. (SQL: select * from `realty_prod`.`properties` where `realty_prod`.`properties`.`id` = 9326305 limit 1)'
New course: Desktop apps with Electron