/** * 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); } }
public function create(Request $request) { if ($request->isMethod('get')) { $data['kokis'] = Koki::all(); return view('resep.create', $data); } 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'); } }
/** * 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); } }
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]); } }); Route::get('drop-create-database', function () { $db = DB::connection()->getDatabaseName(); DB::statement('DROP DATABASE `' . $db . '`'); DB::statement('CREATE DATABASE `' . $db . '`'); });