<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Lokasi;
use App\User;

class LokasiServerController extends Controller
{
    public function index()
    {
        $lokasis = Lokasi::all();
        $users = [];
        foreach($lokasis as $lokasi)
        {
            $user = User::find($lokasi->user_id);
            
            if($user == null)
            {
                Lokasi::where('user_id', $lokasi->user_id)->delete();
            }
            else
            {
                $users[] = $user;
            }
        }
        
        return view("kelolalokasi", [
            'lokasis'  => $lokasis,
            'users' => $users,
        ]);
    }
}
