app/Api/V1/Controllers/AllGoodsController.php
/**
     * Search all goods for matching data to create new goods record
     *
     * @param Request $request
     * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
     */
Search all goods for matching data to create new goods record
@param Request $request
@return \Illuminate\Contracts\Pagination\LengthAwarePaginator
Search all goods for matching data to create new goods record @param Request $request @return \ Illuminate \ Contracts \ Pagination \ LengthAwarePaginator
public function pagedIndex(Request $request) {
        $search = $request->input('search');
        $category = $request->input('category');
        $fromDate = $request->input('from_date');
        $toDate = $request->input('to_date');
        $fD = $fromDate;
        $tD = $toDate;
        $perPage = (int)$request->input('per_page');
        if (!$perPage) {
            $perPage = 15;
        }
        if ($fromDate) {
            $fromDate = date('Y-m-d H:i:s', strtotime($fromDate));
        }
        if ($toDate) {
            $toDate = date('Y-m-d H:i:s', strtotime($toDate));
        }
        $query = AllGoods::query()->with('creator')
            ->where(function ($query) use ($search) {
            $query->where('name', 'like', '%' . $search . '%')
                ->orWhere('short_description', 'like', '%' . $search . '%');
        });
        if ($category) {
            $query = $query->where(['category_id' => $category]);
        }
        if ($fromDate && $toDate) {
            $query = $query->whereBetween('created_at', [$fromDate, $toDate]);
        } elseif ($fromDate) {
            $query = $query->where('created_at', '>=', $fromDate);
        } elseif ($toDate) {
            $query = $query->where('created_at', '<=', $toDate);
        }
        $result = $query->paginate($perPage);
        $append = [];
        if ($search) $append['search'] = $search;
        if ($fromDate) $append['from_date'] = $fD;
        if ($toDate) $append['from_date'] = $tD;
        if ($category) $append['category'] = $category;
        if ($perPage) $append['per_page'] = $perPage;
        $result->appends($append);
        return $result;
    }
public function pagedIndex ( Request $ request ) { $ search = $ request -> input ( 'search' ) ; $ category = $ request -> input ( 'category' ) ; $ fromDate = $ request -> input ( 'from_date' ) ; $ toDate = $ request -> input ( 'to_date' ) ; $ fD = $ fromDate ; $ tD = $ toDate ; $ perPage = ( int ) $ request -> input ( 'per_page' ) ; if ( ! $ perPage ) { $ perPage = 15 ; } if ( $ fromDate ) { $ fromDate = date ( 'Y-m-d H:i:s' , strtotime ( $ fromDate ) ) ; } if ( $ toDate ) { $ toDate = date ( 'Y-m-d H:i:s' , strtotime ( $ toDate ) ) ; } $ query = AllGoods :: query ( ) -> with ( 'creator' ) -> where ( function ( $ query ) use ( $ search ) { $ query -> where ( 'name' , 'like' , '%' . $ search . '%' ) -> orWhere ( 'short_description' , 'like' , '%' . $ search . '%' ) ; } ) ; if ( $ category ) { $ query = $ query -> where ( [ 'category_id' => $ category ] ) ; } if ( $ fromDate && $ toDate ) { $ query = $ query -> whereBetween ( 'created_at' , [ $ fromDate , $ toDate ] ) ; } elseif ( $ fromDate ) { $ query = $ query -> where ( 'created_at' , '>=' , $ fromDate ) ; } elseif ( $ toDate ) { $ query = $ query -> where ( 'created_at' , '<=' , $ toDate ) ; } $ result = $ query -> paginate ( $ perPage ) ; $ append = [ ] ; if ( $ search ) $ append [ 'search' ] = $ search ; if ( $ fromDate ) $ append [ 'from_date' ] = $ fD ; if ( $ toDate ) $ append [ 'from_date' ] = $ tD ; if ( $ category ) $ append [ 'category' ] = $ category ; if ( $ perPage ) $ append [ 'per_page' ] = $ perPage ; $ result -> appends ( $ append ) ; return $ result ; }
Search all goods for matching data to create new goods record
 @param Request $request
 @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
Search all goods for matching data to create new goods record @param Request $request @return \ Illuminate \ Contracts \ Pagination \ LengthAwarePaginator