Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function delete($id)
 {
     //
     $item = Koki::find($id);
     $item->delete();
     return redirect('bahan');
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 public function update(Request $request, $id)
 {
     if ($request->isMethod('get')) {
         $data['item'] = Resep::find($id);
         $data['kokis'] = Koki::all();
         return view('resep.update', $data);
     } elseif ($request->isMethod('post')) {
         $item = Resep::find($id);
         $item->nama = Input::get('nama');
         $item->kode = Input::get('kode');
         $item->koki_id = Input::get('koki_id');
         $item->save();
         return redirect('resep');
     }
 }
Ejemplo n.º 5
0
Route::get('/resep', 'ResepController@index');
Route::get('/resep/create', 'ResepController@create');
Route::post('/resep/create', array('before' => 'csrf', 'uses' => 'ResepController@create'));
Route::get('/resep/update/{id}', 'ResepController@update');
Route::post('/resep/update/{id}', array('before' => 'csrf', 'uses' => 'ResepController@update'));
Route::get('/resep/delete/{id}', 'ResepController@delete');
Route::get('/resep/detail/{id}', 'ResepController@detail');
Route::get('/somerouteshere', 'ResepController@index');
Route::get('/somerouteshere/create', 'ResepController@create');
Route::post('/somerouteshere/create', array('before' => 'csrf', 'uses' => 'ResepController@create'));
Route::get('/somerouteshere/update/{id}', 'ResepController@update');
Route::post('/somerouteshere/update/{id}', array('before' => 'csrf', 'uses' => 'ResepController@update'));
Route::get('/somerouteshere/delete/{id}', 'ResepController@delete');
Route::get('/koki-auto-create', function () {
    for ($i = 0; $i < 10; $i++) {
        \App\Models\Koki::create(['nama' => 'koki' . $i, 'kode' => 'ko' . $i]);
    }
});
Route::get('/koki-resep-auto', function () {
    for ($i = 0; $i < 10; $i++) {
        for ($j = 0; $j < 5; $j++) {
            \App\Models\Resep::create(['koki_id' => $i + 1, 'nama' => 'resepmilikkoki_' . $i . 'nomer' . $j]);
        }
    }
});
Route::get('/generate-bahan', function () {
    $bahans = ['tepung', 'gula', 'telur', 'garam', 'mentega', 'ayam'];
    foreach ($bahans as $bahan) {
        \App\Models\Bahan::create(['nama' => $bahan]);
    }
});
Ejemplo n.º 6
0
 public function delete($id)
 {
     $item = Koki::find($id);
     $item->delete();
     return redirect('koki');
 }
Ejemplo n.º 7
0
 public function detail($id)
 {
     $koki = Koki::findOrFail($id);
     return view('koki.detail', compact('koki'));
 }