Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7.  
  8. class UserController extends Controller
  9. {
  10. public function index(Request $request) {
  11. $xml = simplexml_load_file($request->file);
  12. $select = trim($xml->SELECT);
  13. $from = strtolower(trim($xml->FROM));
  14. $wheres = $xml->WHERE;
  15. $where = '';
  16. $params = [
  17. 'class' => 2,
  18. 'gender' => 0,
  19. 'birthday' => '2019-10-10'
  20. ];
  21. foreach ($wheres as $key => $value) {
  22. $a = strtolower(trim($value));
  23. $b = explode(' ', $a);
  24.  
  25. if (in_array($b[0], array_keys($params))) {
  26. if ($where == '') {
  27. $where .= strtolower(trim($value));
  28. } else {
  29. $where .= ' AND ' . strtolower(trim($value));
  30. }
  31. }
  32. }
  33. $query = 'SELECT ' . $select . ' FROM ' . $from . ' WHERE ' . $where;
  34. $result = DB::select($query, $params);
  35. dd($result);
  36. dd($xml);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement