public static function store() { self::check_logged_in(); $params = $_POST; $attributes = array('fname' => $params['fname'], 'price' => $params['price'], 'sale' => $params['sale'], 'description' => $params['description'], 'orderit' => $params['orderit']); $tuote = new Tuote($attributes); $errors = $tuote->errors(); if (count($errors) == 0) { $tuote->save(); $id = $tuote->id; $tuoteryhmat = $params['tuoteryhmat']; foreach ($tuoteryhmat as $tuoteryhma) { $tuote->createTuoteYhdiste($id, $tuoteryhma); } Redirect::to('/tuote/' . $tuote->id, array('message' => 'Uusi tuote on luotu')); } else { $tuoteryhmat = Tuoteryhma::all(); View::make('tuote/new.html', array('errors' => $errors, 'attributes' => $attributes, 'tuoteryhmat' => $tuoteryhmat)); } }