app/Http/Controllers/Leave/LeaveRequests.php
//gets all leave requests for employees
gets all leave requests for employees
gets all leave requests for employees
public function index(Request $request,Manager $fractal){
        $search = $request->query('search');
        $limit = $request->query('limit', 10);
        $pagingAppends = ['limit' => $limit];
        $company = $this->company();
        $user = $company->users()->where('uuid',$request->input('user_id'))->firstOrFail();
        $employee_id = $company->employees()->where('user_id',$user->id)->firstOrFail()->id;
        if (empty($search)) {
            $paginator = \App\Models\LeaveRequests::where(function ($query) use ($search,$company,$employee_id) {
                return $query->where('company_id',$company->id)
                             ->where('employee_id',$employee_id);
            })
                ->oldest()
                ->paginate($limit);
        }
        else{
            $paginator = \App\Models\LeaveRequests::search($search)
                ->where('company_id', $company->id)
                ->where('employee_id', $employee_id)
                ->paginate($limit);
        }
        $resource = new Collection($paginator->getCollection(), new LeaveRequestsTransformer(), 'leaveRequests');
        if (!empty($search)) {
            $pagingAppends['search'] = $search;
            $resource->setMetaValue('search', $search);
        }
        $paginator->appends($pagingAppends);
        $resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
        return response()->json($fractal->createData($resource)->toArray());
    }
public function index ( Request $ request , Manager $ fractal ) { $ search = $ request -> query ( 'search' ) ; $ limit = $ request -> query ( 'limit' , 10 ) ; $ pagingAppends = [ 'limit' => $ limit ] ; $ company = $ this -> company ( ) ; $ user = $ company -> users ( ) -> where ( 'uuid' , $ request -> input ( 'user_id' ) ) -> firstOrFail ( ) ; $ employee_id = $ company -> employees ( ) -> where ( 'user_id' , $ user -> id ) -> firstOrFail ( ) -> id ; if ( empty ( $ search ) ) { $ paginator = \ App \ Models \ LeaveRequests :: where ( function ( $ query ) use ( $ search , $ company , $ employee_id ) { return $ query -> where ( 'company_id' , $ company -> id ) -> where ( 'employee_id' , $ employee_id ) ; } ) -> oldest ( ) -> paginate ( $ limit ) ; } else { $ paginator = \ App \ Models \ LeaveRequests :: search ( $ search ) -> where ( 'company_id' , $ company -> id ) -> where ( 'employee_id' , $ employee_id ) -> paginate ( $ limit ) ; } $ resource = new Collection ( $ paginator -> getCollection ( ) , new LeaveRequestsTransformer ( ) , 'leaveRequests' ) ; if ( ! empty ( $ search ) ) { $ pagingAppends [ 'search' ] = $ search ; $ resource -> setMetaValue ( 'search' , $ search ) ; } $ paginator -> appends ( $ pagingAppends ) ; $ resource -> setPaginator ( new IlluminatePaginatorAdapter ( $ paginator ) ) ; return response ( ) -> json ( $ fractal -> createData ( $ resource ) -> toArray ( ) ) ; }
gets all leave requests for employees
gets all leave requests for employees
# get the search term in the query, if any # the maximum number of customers to return # retrieve the company # append values for the paginator # searching for something //        $approval_id = $company->approvals()->where('uuid', $request->query('approval_id'))->firstOrFail()->id; # get the orders # create the resource # append the search term to the paginator # set the meta value if necessary # add the append terms # set the paginator