public function store(ReceiveItemUploadRequest $request, UploadReceiveItem $upload, $id) { $receive = Receive::find($id); $file = $request->file('file'); $upload->upload($file->getRealPath(), $id); if (empty($upload->getErrors()) && !empty($upload->getData())) { $responseSave = $upload->save($receive); Log::debug('update-receive-item: save', [$responseSave]); flash()->success(trans('receive.label.name'), trans('receive_item_upload.message_alert.success')); return ['status' => 'success', 'urlRedirect' => url("/receives/add-products/{$id}")]; } return ['status' => 'error', 'errors' => $upload->getErrors()]; }
/** * Bootstrap the application services. * * @return void */ public function boot() { Validator::extend('receive_item_exists', function ($attribute, $value, $parameters, $validator) { $receive = Receive::with(['receiveItems'])->whereHas('receiveItems', function ($query) use($value) { $query->where('product_code', $value); })->whereId($parameters[0])->first(); if ($receive == null) { return false; } return true; }); Validator::replacer('receive_item_exists', function ($message, $attribute, $rule, $parameters) { return $message; }); }
public function editReceive($id) { $rules = ['po_no' => ['po_no' => 'required'], 'ref_no' => ['ref_no' => 'required'], 'project_id' => ['project_id' => 'required']]; $pk = request()->get('pk'); $value = request()->get('value'); $attribute = request()->get('name'); $data = [$attribute => $value]; $validator = Validator::make($data, $rules[$attribute]); if ($validator->passes()) { $receive = Receive::find($pk); if ($attribute == 'project_id') { $receive->{$attribute} = $value; $receive->project_code = Project::find($value)->code; } else { $receive->{$attribute} = $value; } $receive->save(); return Response::json('success', 200); } return Response::json($validator->errors()->first($attribute), 422); }
/** * @param $receive_id * @param $product_code * @param $location * * @return bool */ public static function checkReceiveItemExists($receive_id, $product_code, $location) { $receive = Receive::whereHas('receiveItems', function ($query) use($product_code, $location) { $query->where('product_code', $product_code); $query->where('location_name', $location); })->whereId($receive_id)->count(); if (!$receive) { return false; } return true; }