/** * Store a newly created faucet in storage. * * @return Response * @internal param Request $request */ public function store() { //Create the validator to process input for validation. $validator = Validator::make(Input::except('send_tweet'), FaucetValidator::validationRulesNew()); //If validator fails, return to the create page - //with input still in form, and accompanied with //the relevant errors. if ($validator->fails()) { return Redirect::to('/admin/faucets/create')->withErrors($validator)->withInput(Input::all()); } //Declare and instantiate a new faucet. $faucet = new Faucet(); //Assign input from the form to the faucet's properties - //except payment processors as this needs to be done separately. $faucet->fill(Input::except('faucet_payment_processors', 'send_tweet')); //Retrieve payment processor ids from multi-select dropdown $paymentProcessorIds = Input::get('faucet_payment_processors'); //Save the faucet, with the filled-in data. $faucet->save(); //Now we have saved a faucet, we can begin inserting associated //payment processors from input - in a many-many relationship. DB::statement('SET FOREIGN_KEY_CHECKS = 0'); foreach ($paymentProcessorIds as $paymentProcessorId) { $faucet->paymentProcessors()->attach((int) $paymentProcessorId); } //Associated the currently logged in user with the new faucet. $faucet->users()->attach(Auth::user()->id); // Re-enable foreign key checks after inserting //many-many records. DB::statement('SET FOREIGN_KEY_CHECKS = 1'); //Redirect to the faucet's page, with a success message. Session::flash('success_message', 'The faucet has successfully been created and stored!'); if (Input::get('send_tweet') == 1) { $faucetUrl = url('/faucets/' . $faucet->slug); $user = User::find(Auth::user()->id); $twitter = new Twitter($user); $twitter->sendTweet("Hey everyone, just added another #Bitcoin faucet @ " . $faucetUrl . ". Check it out now! #FreeBTCWebsite"); } return Redirect::to('/faucets/' . $faucet->slug); }