Downloads
Stars
Version
Provides a convenient way of setting up and making requests to the RAWG API from a Laravel application. For RAWG endpoint documentation, rate limits and licencing please visit the RAWG API Docs.
Install the package via Composer:
composer require dherran/laravel-rawg
Publish the configuration file using php artisan vendor:publish --provider="Rawg\RawgServiceProvider"
or simply copy the package configuration file and paste it into config/rawg.php
Open the config file config/rawg.php
and add your app API Key obtainable at https://rawg.io/apidocs.
/*
|----------------------------------
| API Key
|------------------------------------
*/
'api_key' => 'XYZ',
As per the RAWG API Docs: Every API request should have an API Key. If you don’t provide it, we may ban your requests.
Here is an example of making request to Games endpoint:
$response = \Rawg::load('games')->setParams([
'page' => 1,
'page_size' => 40,
'ordering' => '-rating',
])->get();
Or finding details for a specific game:
$response = \Rawg::load('games/{id}')->setParams([
'id' => 86,
])->get();
The principle is that the load method takes the endpoint as provided by RAWG.
load( $serviceName )
- prepare the endpoint name
Accepts string as parameter. You can find all endpoints in the RAWG API Docs. Returns a reference to itself.
\Rawg::load('publishers')
...
setParamByKey( $key, $value )
- set the request parameter using key:value pair
Accepts two parameters:
key
- body parameter namevalue
- body parameter valueDeeply nested arrays can use 'dot' notation to assign values.
Returns a reference to itself.
$endpoint = \Rawg::load('publishers')
->setParamByKey('page', 3)
->setParamByKey('page_size', 10)
...
setParams( $parameters)
- set all request parameters at once
Accepts and array of parameters
Returns a reference to itself.
$response = \Rawg::load('games')
->setParam([
'search' => 'monster',
'tags' => 'multiplayer',
])
...
get()
- performs a RESTful request via GETget($key)
- filter downs the request result. Dot notation is supported here$response = \Rawg::load('games')
->setParamByKey('search', 'monster')
->get();
Example with $key
parameter
$response = \Rawg::load('games')
->setParamByKey('search', 'monster')
->get('results');