Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. public function insert(){
  2. $rules = array(
  3. 'code' => 'required',
  4. 'name' => 'required',
  5. 'category_id' => 'required|numeric',
  6. 'price' => 'numeric',
  7. 'sock_qty' => 'numeric'
  8. );
  9. $messages = array(
  10. 'required' => 'กรุณากรอกข้อมูล Attribute ให้ครบถ้วน',
  11. 'numeric' => 'กรุณากรอกข้อมูล Attribute ให้เป็นตัวเลข'
  12. );
  13. $validator = Validator::make(Input::all(),$rules,$messages);
  14. if($validator->fails()){
  15. return redirect('product/add/')->withErrors($validator)->withInput();
  16. }
  17. $product->code = Input::get('code');
  18. $product->name = Input::get('name');
  19. $product->category_id = Input::get('category_id');
  20. $product->price = Input::get('price');
  21. $product->stock_qty = Input::get('stock_qty');
  22. if(Input::hasFile('image')){
  23. $f = Input::file('image');
  24. $upload_to = 'upload/images';
  25. //get path
  26. $relative_path = $upload_to.'/'.$f->getClientOriginalName();
  27. $absolute_path = public_path().'/'.$upload_to;
  28. //upload file
  29. $f->move($absolute_path,$f->getClientOriginalName());
  30. //save image to database
  31. $product->image_url = $relative_path;
  32. //$product->save();
  33. Image::make(public_path().'/'.$relative_path)->resize(250,250)->save();
  34. $product->save();
  35. }
  36. return redirect('product')->with('ok',true)->with('msg','บันทึก');
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement