Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // my Player Model:
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- class Player extends Model
- {
- public static function getPlayers ($player_region, $player_name) {
- $api_url = 'https://api.dc01.gamelockerapp.com/shards/';
- $api_key = 'my-secret-key';
- $headers = array(
- 'Accept: application/vnd.api+json',
- 'X-TITLE-ID: semc-vainglory',
- 'Authorization: ' . $api_key,
- );
- $options = array('http' => array(
- 'method' => 'GET',
- 'header' => implode("\r\n", $headers),
- ));
- global $api_url, $headers, $options;
- $prefix = 'players';
- $player_query = array(
- 'region' => $player_region,
- 'player_name' => $player_name,
- 'filter' => 'filter[playerNames]=' . $player_name,
- );
- $player_request_uri = 'https://api.dc01.gamelockerapp.com/shards/' . $player_query['region'] . '/' . $prefix . '?' . $player_query['filter'];
- if ($player_return_obj = file_get_contents($player_request_uri, false, stream_context_create($options))) {
- $player_arr = json_decode($player_return_obj, true);
- return $player_arr;
- }
- }
- }
- // my Controller
- public function postPlayer(Request $request){
- $a = $request->playerRegion;
- $b = $request->playerName;
- $data = Player::getPlayers($a, $b);
- }
- // my View
- <!DOCTYPE html>
- <html>
- <head>
- <title>Vainglory</title>
- </head>
- <body>
- <form action="{{route('postPlayer')}}" method="get">
- <input type="text" name="playerName" placeholder="Player Name">
- <input type="text" name="playerRegion" placeholder="Region">
- <input type="submit">
- </form>
- </body>
- </html>
- // Route
- Route::get('/', ['as' => 'displayPlayer', 'uses' => 'PlayerController@getPlayer']);
- Route::get('/player', ['as' => 'postPlayer', 'uses' => 'PlayerController@postPlayer']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement