php laravel route

-Route::get('/', function()
-{
-	return View::make('hello');
+Route::get('/', function () {
+    return View::make('hello');
+});
+
+/* 订单表
+
+task
+
+name, latitude, longitude
+
+*/
+
+Route::get('task', function () {
+    echo '[{"name":"task1", "latitude":"23.0", "longtude":"120.0"},
+    {"name":"task2", "latitude":"23.0", "longtude":"120.0"},
+    {"name":"task3", "latitude":"23.0", "longtude":"120.0"} ]';
+});
+
+Route::get('user/{id}', function ($id) {
+    return 'User ' . $id;
+});
+
+/*
+ * t_db_logins
+ *
+ * username/latitude/longitude
+ */
+
+Route::get('login/{user}/{latitude}/{longitude}', function ($user, $latitude, $longitude) {
+    $dbh = new PDO('mysql:host=localhost;dbname=poly_database', 'root', 'root');
+    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+    $dbh->exec('set names utf8');
+
+    $sql = "CREATE TABLE IF NOT EXISTS t_db_logins
+            (username varchar(255),
+            latitude varchar(255),
+            longitude varchar(255)
+            )";
+
+    $dbh->exec($sql);
+
+    $sql = "DELETE FROM t_db_logins WHERE username ='$user' ";
+    $dbh->exec($sql);
+
+    $sql = "INSERT INTO t_db_logins (username,latitude,longitude) VALUES ('$user', '$latitude$', '$longitude')";
+    $dbh->exec($sql);
+
+    echo '{ "result":"ok"}';
+});
+
+
+Route::get('logins', function () {
+    $dbh = new PDO('mysql:host=localhost;dbname=poly_database', 'root', 'root');
+    $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+    $dbh->exec('set names utf8');
+
+    $sql = "SELECT * FROM t_db_logins";
+
+    try {
+        $result = $dbh->query($sql);
+
+        foreach ($result as $row) {
+            $list[] = array("username" => $row['username'], "latitude" => $row['latitude'], "longitude" => $row['longitude']);
+        }
+
+        echo json_encode($list);
+
+    } catch (PDOException $e) {
+        exit($e->getMessage());
+    }
 });


你可能感兴趣的:(php laravel route)