/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $data) { // Social Media REPEATER $keys = array_keys($data->all()); $k = 0; $socialMedia_ids = array(); foreach ($keys as $key) { if (preg_match('/^screen_name/', $key)) { $keyExploded = explode('-', $key); $socialMedia_ids[$k] = $keyExploded[1]; $k++; } } foreach ($socialMedia_ids as $socialMedia_id) { $socialMediaUpdate = SocialMediaAccount::findOrFail($socialMedia_id); $this->validate($data, ["screen_name-{$socialMedia_id}" => 'required']); // $socialMediaUpdate->account_type = $data["account_type-$socialMedia_id"]; $socialMediaUpdate->screen_name = $data["screen_name-{$socialMedia_id}"]; // $socialMediaUpdate->account_id = $data["account_id-$socialMedia_id"]; $socialMediaUpdate->auto_follow = $data["auto_follow-{$socialMedia_id}"]; $socialMediaUpdate->auto_unfollow = $data["auto_unfollow-{$socialMedia_id}"]; $socialMediaUpdate->auto_whitelist = $data["auto_whitelist-{$socialMedia_id}"]; // $socialMediaUpdate->user_id = Auth::user()->id; $socialMediaUpdate->save(); } return redirect('accounts'); }
/** * Search for a social media account to follow. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function search(Request $request, $id) { $socialMediaAccount = SocialMediaAccount::findOrFail($id); $connection = new TwitterOAuth($socialMediaAccount->consumer_key, $socialMediaAccount->consumer_secret, $socialMediaAccount->access_token, $socialMediaAccount->access_token_secret); $data = $request->get('model_user'); $count = 5; $searchQuery = "https://api.twitter.com/1.1/users/search.json?q={$data}&page=1&count={$count}"; $searchJson = $connection->get("{$searchQuery}"); $bladeVariables = compact('socialMediaAccount', 'searchJson'); $http_code = $connection->http_code; if ($http_code != '200') { $errorMessage = "HTTP code: {$http_code}"; $errorMessage .= "<br><h4>Data Dump</h4>"; $errorMessage .= var_dump($connection); Helper::email_admin($errorMessage, 1, "ModelAccountController", $socialMediaAccount->screen_name); if ($http_code == '401') { return view('errors.401')->with(compact('http_code')); } } else { return view('set-user.show')->with($bladeVariables); } }