Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function storeAdmin(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'name' => 'required|max:191',
- 'stok' => 'required|numeric',
- 'berat_kemasan' => 'required|numeric',
- 'deskripsi' => 'required',
- 'foto_1' => 'required|image',
- 'type' => 'in:distributor,mitra',
- 'kategori_id' => 'required',
- 'satuan' => 'required',
- ]);
- if ($validator->fails()) {
- return response()->json([
- 'success' => false,
- 'messages' => 'Please fill in the blank !',
- 'data' => $validator->errors(),
- ], 403);
- }
- $sizeFotoOne = $_FILES['foto_1']['size'];
- if ($sizeFotoOne > 1048576) {
- $msg = "Ukuran terlalu besar, maksima 1 MB (file". $sizeFotoOne . ")";
- return errorMsg($msg);
- }
- $foto1 = rand(1, 199) . $_FILES['foto_1']['name'];
- $userID = Auth::id();
- $Produk = Produk::create([
- 'name' => $request->input('name'),
- 'stok' => (int) $request->input('stok'),
- 'berat_kemasan' => (double) $request->input('berat_kemasan'),
- 'harga_supplyer' => (int) $request->input('harga_supplyer'),
- 'harga_jual' => (int) $request->input('harga_jual'),
- 'harga_promo' => (int) $request->input('harga_promo'),
- 'expire' => $request->input('expire'),
- 'deskripsi' => $request->input('deskripsi'),
- 'foto_1' => $foto1,
- 'foto_2' => $foto1,
- 'foto_3' => $foto1,
- 'type' => $request->input('type'),
- 'user_id' => $userID,
- 'kategori_id' => $request->input('kategori_id'),
- 'satuan' => $request->input('satuan'),
- 'preorder' => $request->input('preorder'),
- 'preorder_notes' => $request->input('preorder_notes'),
- 'cogs' => (int) $request->input('cogs'),
- 'diskon' => (int) $request->input('diskon'),
- 'margin_pusat' => (int) $request->input('margin_pusat'),
- ]);
- $tempDir = storage_path("temp/");
- move_uploaded_file($_FILES["foto_1"]["tmp_name"], $tempDir . $foto1);
- Storage::disk('produk')->putFileAs($Produk->id, new File($tempDir . $foto1), $foto1);
- if ($Produk) {
- return response()->json([
- 'success' => true,
- 'messages' => 'Add Produk Success !',
- 'data' => $Produk,
- ], 201);
- } else {
- return response()->json([
- 'success' => false,
- 'messages' => 'Can\'t Insert Produk!',
- 'data' => null,
- ], 200);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement