Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $message = ['required' => 'กรุณาใส่ข้อมูล', 'max' => 'ข้อมูลเกิน :max ตัวอักษร', 'email' => 'รูปแบบ email ไม่ถูกต้อง', 'unique_with' => 'ข้อมูลซ้ำ'];
     $rules = array('emp_code' => 'required|unique_with:cos_pcmast,cust_code|max:6', 'cust_code' => 'required', 'emp_name' => 'required|max:50', 'tel' => 'required|max:30', 'email' => 'email|max:30');
     $validator = Validator::make(Request::all(), $rules, $message);
     if ($validator->passes()) {
         $data_pc = array('cust_code' => 'CXXXX', 'emp_code' => Request::get('emp_code'), 'emp_name' => Request::get('emp_name'), 'tel' => Request::get('tel'), 'email' => Request::get('email'), 'created_by' => 'admin', 'updated_by' => 'admin');
         //Insert data to model Entity
         $add_data = Pcmast::create($data_pc);
         //dd($data_entity);
         /* **********  Save Data ************ */
         // Reload Table Data
         $data_pc = array('pc' => Pcmast::where('cust_code', 'CXXXX')->orderBy('emp_code', 'asc')->get(), 'refresh' => true);
         return view('sales.pc_table')->with($data_pc);
     } else {
         if (Request::ajax()) {
             return view('sales.pc_create')->withErrors($validator)->withInput(Request::all());
         }
         return 0;
     }
 }