/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); $input['user_id'] = Auth::user()->id; $validation = Validator::make($input, Palette::$rules); if ($validation->passes() && Account::find($input['account_id'])->isMember(Auth::user())) { $this->palette->create($input); return Redirect::route($this->namespace . '.index'); } return Redirect::route($this->namespace . '.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.'); }
/** * Make changes to the database. * * @return void */ public function up() { Schema::table('palettes', function ($table) { $table->create(); $table->increments('id'); $table->string('title'); $table->text('description')->nullable(); $table->integer('user_id')->unsigned(); $table->timestamps(); }); Schema::table('palettes', function ($table) { $table->foreign('user_id')->references('id')->on('users')->on_update('cascade')->on_delete('cascade'); $table->unique(array('title', 'user_id')); }); $seed = array(array('title' => 'Revlon\'s Palette', 'description' => 'Collection of colors used in foundation.', 'user_id' => 1), array('title' => 'Colgates\'s Palette', 'description' => 'Collection of teeth colors used for teeth whitening programs.', 'user_id' => 1), array('title' => 'Clairol\'s Palette', 'description' => 'Collection of colors used for hair dyeing.', 'user_id' => 1)); foreach ($seed as $rec) { Palette::create($rec); } }
public function post_store() { $input = Input::all(); $validation = Validator::make($input, $this->rules); if ($validation->fails()) { return Redirect::back()->with('errors', $validation->errors)->with_input(); //Need to send errors back... } $input = Input::all(); $input['user_id'] = 1; // DEVELOPMENT!!!!!!!!!!!!! try { $palette = Palette::create($input); } catch (Exception $e) { return Redirect::back()->with('error', "There was an error with your submission! Please try again.")->with_input(); } if ($palette) { return Redirect::to('litmus/palettes/' . $palette->id)->with('status', 'Your palette was submitted successfully!'); } }