public function get_keyword_id($keyword) { if (null !== $keyword) { if ($result = Keyword::where('name', $keyword)->first()) { return $result->id; } else { return 1; } } else { return 1; } }
/** * Run the database seeds. * * @return void */ public function run() { $flags = array('Starbucks' => array('alternatives' => array(array('title' => 'Tim Hortons', 'data' => array('savings_percent' => 40, 'message' => 'Tim Horton\'s costs much less than Starbucks.')), array('title' => 'Make Coffee At Home', 'data' => array('savings_percent' => 60, 'message' => 'Save a ton of money by making your own coffee.'))), 'keywords' => array('starbucks')), 'Loblaws' => array('alternatives' => array(array('title' => 'Metro', 'data' => array('savings_percent' => 30, 'message' => 'Big savings by shopping at Metro vs other stores.'))), 'keywords' => array('sobeys', 'loblaw', 'zehrs')), 'Casino' => array('alternatives' => array(array('title' => 'Don\'t Gamble', 'data' => array('savings_percent' => 100, 'message' => 'Instead of losing money by gambling, we can instantly use that to cover debts.'))), 'keywords' => array('casino'))); foreach ($flags as $key => $flag) { $new_flag = Flag::create(['title' => $key]); foreach ($flag['alternatives'] as $alternative) { $new_alternative = Alternative::create(['title' => $alternative['title']]); $new_flag->alternatives()->attach($new_alternative->id, ['savings_percent' => $alternative['data']['savings_percent'], 'message' => $alternative['data']['message']]); } foreach ($flag['keywords'] as $keyword) { $new_flag->keywords()->attach(Keyword::where('name', $keyword)->first()->id); } } }
/** * * @return type */ public function getUrls() { $keyword = Request::input('keyword'); if ($keyword == '') { return Response::json(array('success' => false, 'error' => 'Please enter a keyword'), 400); } $keyword = Keyword::where('value', '=', $keyword)->first(); if ($keyword == '') { return Response::json(array('success' => false, 'error' => 'No urls found for the keyword'), 400); } $urls = Link::where('keyword_id', '=', $keyword->id)->paginate(10); if (Request::ajax()) { return Response::json(View::make('partials.url-list', array('urls' => $urls))->render()); } }
public function processAdvert($campain_id) { $userName = Auth::user()->name; $campain = Campain::find($campain_id); $advert = $campain->advert; $response = ""; try { $ml = new MonkeyLearn\Client('74312b126c6fcee32bddc68b6b3d4b15fee48868'); $text_list = [$advert]; $module_id = 'ex_eV2dppYE'; $res = $ml->extractors->extract($module_id, $text_list); $results = $res->result; $response = $results[0]; } catch (Exception $e) { echo 'Message: ' . $e->getMessage(); } $colors = ['bg-success', 'bg-primary', 'bg-danger', 'bg-warning']; $keywords = []; foreach ($response as $item) { $text = $item["keyword"]; $relevance = $item["relevance"]; $isRegistered = 'Existente'; $color = $colors[array_rand($colors)]; $relevance = $relevance * 100 . "%"; $keyword = Keyword::where('text', '=', $text)->get(); if (count($keyword) == 0) { $isRegistered = 'Nuevo Registro'; $keyword = new Keyword(); $keyword->text = $text; $keyword->save(); } else { $keyword = $keyword[0]; } $link = new Link(); $link->campain_id = $campain_id; $link->keyword_id = $keyword->id; $link->save(); $keywords[] = ["text" => $text, "relevance" => $relevance, "isRegistered" => $isRegistered, "color" => $color]; } return view('campain.result', ['userName' => $userName, 'textArticle' => $advert, 'keywords' => $keywords]); }
$games = Game::latest('update')->paginate(20); return view('games.search', compact('games', 'term', 'pageSearch', 'css', 'page'))->with([ 'title' => 'Hot Search Android Apps - AppForAndroidPhone', 'desc' => '', 'keyword' => '' ]); }); Route::get('search/{tag}', function($tag) { if (preg_match('/tag-([a-z0-9\-]+)/', $tag, $matches)) { $css = 'search'; $page = null; $pageSearch = true; $term = $matches[1]; if (strlen($term) > 2) { $term = str_replace('-',' ', $term); $keyword = Keyword::where('name', $term)->first(); if (!$keyword) { $keyword = new Keyword(); $keyword->create(['name' => $term, 'count' => 1]); } else { $keyword->count ++; $keyword->save(); } $games = Game::tagged($term)->latest('update')->paginate(20); } else { $games = Game::latest('update')->paginate(20); } return view('games.search', compact('games', 'term', 'pageSearch', 'css', 'page'))->with([ 'title' => 'Search result for '.$term.' - AppForAndroidPhone', 'desc' => '', 'keyword' => ''