HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers93/fitale.nl/app/Komma/Blocks/BlockService.php
<?php

namespace Komma\Blocks;

use Illuminate\Support\Collection;
use Komma\Blocks\Models\Block;
use Komma\Images\ImageService;


/**
 *
 * @author      Tim Van Samang <timvansamang@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */
class BlockService
{
    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 blocks with an IN
     *
     * @param $field | string, field for the in
     * @param $values | array, values for the in
     * @return mixed
     */
    public function getBlocksIn($field, $values)
    {
        //Only get the active blocks
        $blocks = Block::where('active', '=', 1)
            //Where in with field and values
            ->whereIn($field, $values)
            //Also load the translation
            ->with('translation')
            ->with('images')
            ->get()
            ->keyBy($field);

        return $blocks;
    }

    /**
     * This method invokes the getBlocksIn
     * With code_name as field
     *
     * @param $code_names
     * @return mixed
     */
    public function getBlocksByCodeName($code_names)
    {
        return $this->getBlocksIn('code_name', $code_names);
    }

    /**
     * This method invokes the getBlocksIn
     * With id as field
     *
     * @param $ids
     * @return mixed
     */
    public function getBlocksById($ids)
    {
        return $this->getBlocksIn('id', $ids);
    }

}