<?php

namespace App\Http\Services;

use App\Models\UserObject;
use App\Models\ObjectModel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;

class ObjectService
{
    public static function getAll(){

        $objects = new ObjectModel;

        if(Auth::user()->type === 'admin'){
            $objects = $objects->get();
            
        }else
        {
            $user_objects = UserObject::where('user_id', Auth::user()->id)->pluck('object_id');
            if(isset($user_objects)){
                $objects = $objects->whereIn('id',$user_objects)->get();
            }else{
                $objects = [];
            }
        }

        return $objects;
    }

}