Giter Site home page Giter Site logo

grigorygerasimov / laravel-weather Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 318 KB

Laravel package based on WeatherAPI

Home Page: https://packagist.org/packages/grigorygerasimov/laravel-weather

PHP 83.77% Blade 16.23%
laravel package php8 php82 php82x weather-api geolocation ip ipsearch weather weather-data weather-forecast

laravel-weather's Introduction

Laravel-Weather Package

Laravel package for weather and geo info based on WeatherAPI (JSON RestAPI only)

Installation

The package can be installed via Composer:

composer require grigorygerasimov/laravel-weather

You don't need to register the package Service Provider - this will be done automatically once you install the package.

For publishing the package config please run the following command. There are also some example views and the package docs under the same tag.

php artisan vendor:publish --tag=laravel-weather

Start

Once the package is installed and the config is published, you are free to use the package in your Laravel projects.

All you need to do is to use the Weather facade (GrigoryGerasimov\Weather\Facades\Weather) and build custom fluent interfaces, e.g.:

Weather::api('forecast')->city('Prague')->forecastDays(3)->requireAQI(true)->requireAlerts(true)->requireTides(true)->lang('cs')->get();

The api() method is mandatory, as it configures the relevant api method and api key.

By default the WeatherAPI Free plan key is used, however you can always adjust it in the laravel-weather config, if you have your own WeatherAPI key.

As for the api methods, the following ones are available.

current
forecast
search
history
marine
future
timezone
sports
astronomy
ip

By default, the current method is used. Please note that the default WeatherAPI Free plan key is limited for the history method.

The available Weather facade methods are:

api(string $type = 'current')
coords(float|string $lat, float|string $lon)
city(string $city)
zip(string $zipCode)
metar(string $metarCode)
iata(string $iataCode)
autoIp()
ip(string $ip)
forecastDays(int $days = 1)
historyFutureDate(string $date)
historyDate(string $date)
forecastHistoryTimestamp(string|int $timestamp)
historyTimestamp(string|int $timestamp)
forecastHistoryHour(int $hour)
requireAlerts(bool $shouldAlert = false)
requireAQI(bool $ifAqi = false)
requireTides(bool $ifTides = false)
withInterval()
lang(string $langCode)
get()
uri()

The facade method get() will provide you with the result of your request, however you can also access the request uri directly via the uri() method.

For demonstration purpose, the package also includes a number of components and views to the basic Weather api methods. These views are some very simple data lists without any particular styling, they serve merely for the visual representation of the weather and geo info retrieved with the help of this package. You can check them out under the following web-routes

For further details, you can also check the weather controller and components

Screenshot 2023-06-18 at 11 25 36 Screenshot 2023-06-18 at 11 26 11 Screenshot 2023-06-18 at 11 26 43 Screenshot 2023-06-18 at 11 27 33

Documentation

For the detailed infos on the package structure and api, please refer to the Laravel-Weather documentation which is published into your public folder. While running the php artisan serve command, you can access the docs as follows:

http://localhost:8000/vendor/laravel-weather/docs/index.html

Please don't forget to refer to the official WeatherAPI documentation to get a better glimpse of the weather and geo data via a JSON RestAPI.

License

The package is under MIT license, thus you are free to use it in your projects.

Feedback

As I've never had any previous experience in creating packages, I would appreciate some feedback: whether the Laravel-Weather package is easy/hard to use, what can be improved etc.

Feel free to get in touch with me under [email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.