![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/mcoil.corals.io/app/Shop/Quotations/Repositories/ |
<?php namespace App\Shop\Quotations\Repositories; use InvalidArgumentException; use App\Shop\Quotations\Quotation; use Illuminate\Support\Collection; use Jsdecena\Baserepo\BaseRepository; use Illuminate\Database\QueryException; use Illuminate\Database\Eloquent\ModelNotFoundException; use App\Shop\Quotations\Repositories\Interfaces\QuotationRepositoryInterface; class QuotationRepository extends BaseRepository implements QuotationRepositoryInterface { /** * QuotationRepository constructor. * * @param Quotation $dummy */ public function __construct(Quotation $dummy) { parent::__construct($dummy); $this->model = $dummy; } /** * List all the Quotations * * @param string $order * @param string $sort * @param array $except * @return \Illuminate\Support\Collection */ public function listQuotations(string $order = 'id', string $sort = 'desc', $except = []) : Collection { return $this->model->orderBy($order, $sort)->get()->except($except); } /** * Create Quotation * * @param array $params * * @return Quotation * @throws InvalidArgumentException */ public function createQuotation(array $params) : Quotation { try { return Quotation::create($params); } catch (QueryException $e) { throw new InvalidArgumentException($e->getMessage()); } } /** * Update the dummy * * @param array $params * @return Quotation */ public function updateQuotation(array $params) : Quotation { $dummy = $this->findQuotationById($this->model->id); $dummy->update($params); return $dummy; } /** * @param int $id * * @return Quotation * @throws ModelNotFoundException */ public function findQuotationById(int $id) : Quotation { try { return $this->findOneOrFail($id); } catch (ModelNotFoundException $e) { throw new ModelNotFoundException($e->getMessage()); } } /** * Delete a dummy * * @return bool */ public function deleteQuotation() : bool { return $this->model->delete(); } /** * * @return Collection */ public function listStatus() : Collection { return $this->model->status()->get(); } /** * @param string $text * @return mixed */ public function searchQuotations(string $text = null) : Collection { if (is_null($text)) { return $this->all(); } return $this->model->searchQuotations($text)->get(); } public function searchQuotationsWithParameters(string $text = null, array $filters = []) : Collection { $search = $this->model->with('customer')->where('title','like', "%{$text}%"); $search = $search->get(); return $search; } public function searchByCode(string $code) { return $this->model->with('customer')->with('items')->with('business')->where('code', $code)->first(); } }