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()]; }
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); }