Пример #1
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create(HttpRequest $request)
 {
     //
     //Cara 1
     // $item = new Resep();
     // $item->nama = "tepung maizena";
     // $item->kode = "BHN01";
     // $item->save();
     // return redirect('resep');
     //        cara 2
     // $item = array('nama' => "telur ayam",'kode' => "BHN02");
     // Resep::create($item);
     if (Request::isMethod('get')) {
         //$items['koki']  = Koki::all();
         //return view('resep.create',$items);
         $bahans = Bahan::get();
         $kokis = Koki::get();
         return view('resep.create', compact('bahans', 'kokis'));
     } elseif (Request::isMethod('post')) {
         //$item= array('nama' =>Input::get('nama')
         //             ,'kode' =>Input::get('kode')
         //             ,'koki_id'=>Input::get('koki_id'));
         //Resep::create($item);
         //return redirect('resep');
         //dd(Input::all());
         //Resep::create($item);
         //return redirect('resep');
         $this->validate($request, $this->inputRules, $this->locale(), $this->customAtributes);
         $newResep = Resep::create(Input::all());
         $bahan_ids = Input::get('bahan_ids');
         $newResep->bahan()->attach($bahan_ids);
         return redirect('resep/detail/' . $newResep->id);
     }
 }
Пример #2
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function create(HttpRequest $request)
 {
     if (Request::isMethod('get')) {
         $bahans = Bahan::get();
         $kokis = Koki::get();
         return view('resep.create', compact('bahans', 'kokis'));
     } elseif (Request::isMethod('post')) {
         $this->validate($request, $this->inputRules, $this->locale(), $this->customAtributes);
         $newResep = Resep::create(Input::all());
         $bahan_ids = Input::get('bahan_ids');
         $newResep->bahan()->attach($bahan_ids);
         return redirect('resep/detail/' . $newResep->id);
     }
 }