App\Ninja\Repositories\ProductRepository::find PHP Method

find() public method

public find ( $accountId, $filter = null )
    public function find($accountId, $filter = null)
    {
        $query = DB::table('products')->leftJoin('tax_rates', function ($join) {
            $join->on('tax_rates.id', '=', 'products.default_tax_rate_id')->whereNull('tax_rates.deleted_at');
        })->where('products.account_id', '=', $accountId)->select('products.public_id', 'products.product_key', 'products.notes', 'products.cost', 'tax_rates.name as tax_name', 'tax_rates.rate as tax_rate', 'products.deleted_at');
        if ($filter) {
            $query->where(function ($query) use($filter) {
                $query->where('products.product_key', 'like', '%' . $filter . '%')->orWhere('products.notes', 'like', '%' . $filter . '%');
            });
        }
        if (!\Session::get('show_trash:product')) {
            $query->where('products.deleted_at', '=', null);
        }
        return $query;
    }

Usage Example

 /**
  * @param $accountId
  * @return \Illuminate\Http\JsonResponse
  */
 public function getDatatable($accountId, $search)
 {
     $datatable = new ProductDatatable(true);
     $query = $this->productRepo->find($accountId, $search);
     if (!Utils::hasPermission('view_all')) {
         $query->where('products.user_id', '=', Auth::user()->id);
     }
     return $this->datatableService->createDatatable($datatable, $query);
 }
All Usage Examples Of App\Ninja\Repositories\ProductRepository::find