Quellcode durchsuchen

Merge branch 'Kotenko' of gitgod/geolook into master

Serge vor 5 Jahren
Ursprung
Commit
70b4b8320d
3 geänderte Dateien mit 33 neuen und 1 gelöschten Zeilen
  1. 25 0
      app/Http/Controllers/UserController.php
  2. 4 0
      app/User.php
  3. 4 1
      routes/web.php

+ 25 - 0
app/Http/Controllers/UserController.php

@@ -0,0 +1,25 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\User;
+use Illuminate\Http\Request;
+
+class UserController extends Controller
+{
+    public function index(){
+        $locations = [];
+        foreach (User::all() as $user){
+            $locations[] = $user->locations;
+        }
+        return $locations;
+    }
+
+    public function show(User $id){
+        return $id->locations;
+    }
+
+    public function showLast(User $id){
+        return $id->lastCoordinates;
+    }
+}

+ 4 - 0
app/User.php

@@ -48,4 +48,8 @@ class User extends Authenticatable
     public function groups(){
         return $this->belongsToMany(Group::class);
     }
+
+    public function getLastCoordinatesAttribute(){
+        return self::locations()->orderBy('created_at', 'desc')->first();
+    }
 }

+ 4 - 1
routes/web.php

@@ -19,4 +19,7 @@ Auth::routes();
 
 Route::get('/home', 'HomeController@index')->name('home');
 
-Route::resource('contacts', 'ContactController');
+Route::get('/user', 'UserController@index')->name('all.positions');
+Route::get('/user/{id}', 'UserController@show')->where('id', '[0-9]+')->name('user.position');
+Route::get('/user/{id}/last', 'UserController@showLast')->where('id', '[0-9]+')->name('last.position');
+