File: D:/HostingSpaces/SBogers10/rentman.komma.pro/app/Komma/Prices/PriceService.php
<?php
namespace Komma\Prices;
use Illuminate\Support\Collection;
use Komma\Images\ImageService;
use Komma\Prices\Models\Price;
/**
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
class PriceService
{
private $imageService;
/**
* Inject the dependencies.
* Ex. the imageService.
*
* BlockService constructor.
* @param ImageService $imageService
*/
public function __construct(ImageService $imageService)
{
$this->imageService = $imageService;
}
/**
* This method gets the prices with an IN
*
* @param $field | string, field for the in
* @param $values | array, values for the in
* @return mixed
*/
public function getPricesIn($field, $values)
{
//Only get the active blocks
$prices = Price::where('active', '=', 1)
//Where in with field and values
->whereIn($field, $values)
//Also load the translation
->with('translation')
->with('images')
->get()
->keyBy($field);
return $prices;
}
/**
* This method gets the prices where
*
* @param $field | string, field for the where
* @param $values | array, value for the where
* @return mixed
*/
public function getPricesWhere($field, $values)
{
//Only get the active blocks
$blocks = Price::where('active', '=', 1)
//Where field is value
->where($field, '=', $values)
//Also load the translation
->with('translation')
->with('images')
->get();
return $blocks;
}
/**
* This method invokes the getPricesWhere
* With code_name as field
*
* @param $code_names
* @return mixed
*/
public function getPriceByCodeName($code_name)
{
$price = Price::where('active', '=', 1)
//Where field is value
->where('code_name', '=', $code_name)
//Also load the translation
->with('translation')
->with('images')
->first();
return $price;
}
/**
* This method invokes the getPricesIn
* With id as field
*
* @param $ids
* @return mixed
*/
public function getPricesById($ids)
{
return $this->getPricesIn('id', $ids);
}
}