12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Admin\Repositories;
- use App\Traits\DistSlugTrait;
- use Dcat\Admin\Form;
- use App\Models\DistProduct as Model;
- use Dcat\Admin\Repositories\EloquentRepository;
- class DistProduct extends EloquentRepository
- {
- use DistSlugTrait;
-
- protected $eloquentClass = Model::class;
- public function delete(Form $form, array $originalData)
- {
- collect(explode(',', $form->getKey()))->filter()->each(function ($id) {
- $product = Model::find($id);
- if ($product) {
-
- if ($product->dist_id !== getDistributorId()) {
- throw new \Exception('Unable to modify the product because the distributor ID does not match.');
- return;
- }
- Model::find($id)->images()->delete();
- Model::find($id)->delete();
- }
- });
- return true;
- }
- public static function findById($id)
- {
- return Model::find($id);
- }
-
- public static function selectOptionsNew($limit=30)
- {
- return Model::where('dist_id', getDistributorId())->where('enabled', 1)->orderBy('created_at', 'desc')->limit($limit)->pluck('title', 'id');
- }
-
- public static function getOneById($id)
- {
- return Model::where('id', $id)->where('dist_id', getDistributorId())->first();
- }
-
- public static function auditProduct($id , $status , $reviewReply) {
- $product = Model::find($id);
- if ($product) {
- $product->status = $status;
- $product->review_reply = $reviewReply;
- $product->save();
- }
- return true;
- }
- }
|