Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function insert(){
- $rules = array(
- 'code' => 'required',
- 'name' => 'required',
- 'category_id' => 'required|numeric',
- 'price' => 'numeric',
- 'sock_qty' => 'numeric'
- );
- $messages = array(
- 'required' => 'กรุณากรอกข้อมูล Attribute ให้ครบถ้วน',
- 'numeric' => 'กรุณากรอกข้อมูล Attribute ให้เป็นตัวเลข'
- );
- $validator = Validator::make(Input::all(),$rules,$messages);
- if($validator->fails()){
- return redirect('product/add/')->withErrors($validator)->withInput();
- }
- $product->code = Input::get('code');
- $product->name = Input::get('name');
- $product->category_id = Input::get('category_id');
- $product->price = Input::get('price');
- $product->stock_qty = Input::get('stock_qty');
- if(Input::hasFile('image')){
- $f = Input::file('image');
- $upload_to = 'upload/images';
- //get path
- $relative_path = $upload_to.'/'.$f->getClientOriginalName();
- $absolute_path = public_path().'/'.$upload_to;
- //upload file
- $f->move($absolute_path,$f->getClientOriginalName());
- //save image to database
- $product->image_url = $relative_path;
- //$product->save();
- Image::make(public_path().'/'.$relative_path)->resize(250,250)->save();
- $product->save();
- }
- return redirect('product')->with('ok',true)->with('msg','บันทึก');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement