PHPackages                             lawnstarter/laravel-darksky - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. lawnstarter/laravel-darksky

AbandonedArchivedLibrary[API Development](/categories/api)

lawnstarter/laravel-darksky
===========================

Provides a Wrapper for the DarkSky API

v2.1.0(6y ago)012.9kMITPHPPHP &gt;=5.4.0

Since Jun 14Pushed 6y ago3 watchersCompare

[ Source](https://github.com/lawnstarter/laravel-darksky)[ Packagist](https://packagist.org/packages/lawnstarter/laravel-darksky)[ Docs](https://github.com/lawnstarter/laravel-darksky)[ RSS](/packages/lawnstarter-laravel-darksky/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (3)Versions (17)Used By (0)

Laravel DarkSky
---------------

[](#laravel-darksky)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

This provides a Laravel style wrapper for the DarkSky api and simplifies writing tests against ever changing weather data. For more information regarding request and response formats, visit:

### Install

[](#install)

Require this package with composer using the following command:

```
$ composer require lawnstarter/laravel-darksky
```

After updating composer, add the service provider to the `providers` array in `config/app.php`

```
Lawnstarter\LaravelDarkSky\LaravelDarkSkyServiceProvider::class,
```

To register a facade accessor, add the following to `config/app.php` `aliases` array

```
'DarkSky' => \Lawnstarter\LaravelDarkSky\Facades\DarkSky::class,
```

### Configuration

[](#configuration)

Add the following line to the .env file:

```
DARKSKY_API_KEY=
```

### Usage

[](#usage)

For full details of response formats, visit:

#### Required

[](#required)

##### location(lat, lon)

[](#locationlat-lon)

Pass in latitude and longitude coordinates for a basic response

```
DarkSky::location(lat, lon)->get();
```

#### Optional Parameters

[](#optional-parameters)

For full details of optional parameters, visit:

##### excludes(\[\]) / includes(\[\])

[](#excludes--includes)

Specify which data blocks to exclude/include to reduce data transfer

```
DarkSky::location(lat, lon)->excludes(['minutely','hourly', 'daily', 'alerts', 'flags'])->get();
DarkSky::location(lat, lon)->includes(['currently'])->get();
// Same output
```

##### atTime(t)

[](#attimet)

Pass in a unix timestamp to get forecast for that time. Note: the timezone is relative to the given location

```
DarkSky::location(lat, lon)->atTime(timestamp)->get();
```

##### language(l)

[](#languagel)

Specify a language for text based responses

```
DarkSky::location(lat, lon)->language(lang)->get();
```

##### units(u)

[](#unitsu)

Specify units for unit based responses

```
DarkSky::location(lat, lon)->units(units)->get();
```

##### extend()

[](#extend)

Extend the "hourly" response from 48 to 168 hours. Note: Does not work if used with an atTime() timestamp. Please see:

```
DarkSky::location(lat, lon)->extend()->get();
```

#### Helpers

[](#helpers)

The following are shorthand helpers to add readability equal to using includes() with only one parameter. Note: only one may be used per query and only temperature specific data is returned

```
->currently()
->minutely()
->hourly()
->daily()
->flags()
```

For example, these two statements are the same

```
DarkSky::location(lat, lon)->hourly()
DarkSky::location(lat, lon)->includes(['hourly'])->get()->hourly
```

### DarkSky &amp; Testing

[](#darksky--testing)

To simplyfiy testing the static method to force the response to be a certain payload without actually hitting the DarkSky API was added.

```
DarkSky::setTestResponse($testResponseValue);
```

When this value is not null, the DarkSky wrapper will always return this data. If the value is null, the DarkSky API will be queried in real-time. To simplify testing further, sample test responses are available for you to use in your test classes

```
