/home/mip/mip/app/Modules/Client/Repositories/Products/ProductBrandRepository.php
<?php

namespace QxCMS\Modules\Client\Repositories\Products;

use QxCMS\Modules\AbstractRepository;
use QxCMS\Modules\Client\Models\Products\ProductBrand;
use QxCMS\Modules\Client\Repositories\Products\ProductRepositoryInterface as Product;

use Illuminate\Http\Request;

class ProductBrandRepository extends AbstractRepository implements ProductBrandRepositoryInterface
{

    protected $model;

    function __construct(ProductBrand $model, Product $product)
    {
        $this->model = $model;
        $this->product = $product;
    }

    public function create(array $request)
    {
        $productBrand = $this->model->fill($request);
        $productBrand->save();
        return $productBrand;
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $name = $request->input('name');

        $productBrand = $this->findById($id);
        $productBrand->name = $name;
        $productBrand->save();
        return $productBrand->name;
    }

    public function delete($id)
    {
        $productBrand = $this->findById($id);
        if ($productBrand->product->count() > 0) {
            return response()->json(['error' => 'exists', 'id' => $id]);
        } else {
            $productBrand->delete();
            return response()->json(['success' => 'yes', 'id' => $id]);
        }            
    }

    public function productBrandList()
    {
        return
            $this
            ->model
            ->orderBy('name','asc')
            ->pluck('name', 'id')
            ->toArray();
    }

}