public function index() { $boardgames = Boardgame::all(); $mostPlayedGames = \DB::table('events')->join('boardgames', 'boardgames.id', '=', 'events.boardgame_id')->whereNotNull('events.boardgame_id')->groupBy('events.boardgame_id')->select(array('boardgames.*', \DB::raw('count(*) AS c')))->take(10)->orderBy('c', 'desc')->get(); $nearEvents = \DB::table('events')->join('users', 'events.user_id', '=', 'users.id')->join('boardgames', 'boardgames.id', '=', 'events.boardgame_id')->where('event_date', '>', date('Y-m-d H:i'))->take(10)->orderBy('event_date', 'asc')->get(['users.name as host', 'users.avatar as host_avatar', 'events.name', 'boardgames.name as game_name', 'boardgames.image as game_image', 'boardgames.url as game_url']); $var = ["mostPlayedGames" => $mostPlayedGames, "boardgames" => $boardgames, "nearEvents" => $nearEvents]; return view('home.index', $var); }
/** * Run the database seeds. * * @return void */ public function run() { \DB::table('boardgames')->delete(); $xml = file_get_contents("http://www.boardgamegeek.com/xmlapi/collection/Kondov"); $xml = simplexml_load_string($xml); $json = json_encode($xml); $collection = json_decode($json, TRUE); $i = 1; foreach ($collection['item'] as $game) { $boardgame = new Boardgame(); $boardgame->id = $i; $boardgame->name = $game['name']; $boardgame->description = 'description'; $boardgame->url = "https://boardgamegeek.com/boardgame/" . $game['@attributes']['objectid']; $boardgame->image = $game['image']; $boardgame->save(); $i++; } }
public function shortDetails($id) { $event = Event::find($id); $hostId = $event->user_id; $gameId = $event->boardgame_id; $boardGame = Boardgame::find($gameId); $user = User::find($hostId); $flagApproveEnable = \DB::table('event_user')->where('event_id', '=', $event->id)->where('user_id', '=', \Auth::id())->count() == 0; $event->event_date_formated = Date('g:ia \\o\\n jS F Y', strtotime($event->event_date)); $peopleCount = \DB::table('event_user')->where('event_id', $id)->where('status', 'approved')->count(); $event->people_count = $peopleCount; $flagApproveEnable = true; $var = ['event' => $event, 'user' => $user, 'boardGame' => $boardGame, 'flagApproveEnable' => $flagApproveEnable]; return view('events.short-details', $var); }