Integrate Astrel to your Laravel applications.

Related tags

Laravel config laravel
Overview

Astrel Laravel

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Integrate Astrel to your Laravel applications.

Astrel is a remote config orchestration application that enables you to change anything in your apps without touching your code.

🍿 Are you a visual learner? Here a quick video tutorial to help you get started with Astrel and Laravel.

Installation

Install this package via composer.

composer require sustainable-hustle/astrel-laravel

Add your Astrel API key in your .env file.

ASTREL_API_KEY="sxjTgBJAxkT2TNyKf9vabFI0L07AyItM5o3iiloS"

Finally, listen for Astrel's webhooks to clear the cache.

// routes/web.php
use SustainableHustle\Astrel\Facades\Astrel;
Astrel::webhookRoute('astrel/webhook');

// Make sure CSRF verification is disabled on that route.
class VerifyCsrfToken extends Middleware
{
    protected $except = [
        '/astrel/webhook',
    ];
}

Optionally, publish the astrel config file.

php artisan vendor:publish --tag="astrel-config"

Basic usage

This package provides a facade you can use to retrieve one or many aspects. An aspect is a key/value pair that you configure and updates directly on your Astrel dashboard.

use SustainableHustle\Astrel\Facades\Astrel;

Astrel::all();                        // Returns all aspects.
Astrel::get('slug');                  // Returns the value of an aspect by giving its slug.
Astrel::get('slug', 'default value'); // Returns the default value if the given aspect has no value.

Alternatively, you may use the astrel helper method to access the Astrel manager or to access a value directly.

astrel()->all();                 // Equivalent to Astrel::all();
astrel('slug');                  // Equivalent to Astrel::get('slug');
astrel('slug', 'default value'); // Equivalent to Astrel::get('slug', 'default value');

Note that if you'd like to fallback to an environment variable you may also use the astrel_env helper function like so.

astrel_env('my-slug');                           // Equivalent to astrel('my-slug', env('MY_SLUG'));
astrel_env('my-slug', 'MY_ENV_SLUG');            // Equivalent to astrel('my-slug', env('MY_ENV_SLUG'));
astrel_env('my-slug', 'MY_ENV_SLUG', 'default'); // Equivalent to astrel('my-slug', env('MY_ENV_SLUG', 'default'));

Caching

This package automatically caches all retrieved aspects. This ensure your application does not make API calls every single time a value from Astrel is required.

You may use the flush and refetch methods from the Astrel facade to clear the cache as well as refetching its content immediately.

use SustainableHustle\Astrel\Facades\Astrel;

Astrel::flush()   // Flush the cache for all aspects.
Astrel::refetch() // Flush the cache and refetch all aspects immediately.

By default, the cache never expires meaning you will have to manually flush it when necessary. This is because Astrel will send you a webhook whenever something changes so you can flush the cache only when necessary (see section below).

However, if you'd like to customize the cache's lifetime, you may update the cache_lifetime variable in your config/astrel.php file.

Clear the cache when receiving a webhook

As mentioned above, you can configure Astrel to send you a webhook whenever any value gets updated. That means you can use this webhook to clear and immediately refetch all of your aspects.

This package provides a helper method webhookRoute on the Astrel facade that does just that. Simply add this to your routes file and chain any route configuration you might like.

use SustainableHustle\Astrel\Facades\Astrel;

Astrel::webhookRoute();                 // Register a route that calls `Astrel::refetch()` when triggered.
Astrel::webhookRoute('astrel/webhook'); // Provide a custom path to that route.
Astrel::webhookRoute('astrel/webhook')  // This method returns a Route object so you can chain anything you want.
    ->name('webhooks.astrel')
    ->middleware('web');

Additionally, if you're using the default web middleware group, make sure to disable CSRF verification for that route in the VerifyCsrfToken middleware.

class VerifyCsrfToken extends Middleware
{
    protected $except = [
-       //
+      '/astrel/webhook',
    ];
}
You might also like...
This package lets you add uuid as primary key in your laravel applications

laravel-model-uuid A Laravel package to add uuid to models Table of contents Installation Configuration Model Uuid Publishing files / configurations I

Quickly identify controller methods with no route in your Laravel applications.
Quickly identify controller methods with no route in your Laravel applications.

Orphan Controller Quickly identify controller methods with no route in your Laravel applications. Installation You can install the package via Compose

Run patches migration style in your Laravel applications.
Run patches migration style in your Laravel applications.

This package generates patch files in the same fashion Laravel generates migrations. Each file is timestamped with an up and a down method and is asso

Ensure your Laravel applications keep a normal pulse
Ensure your Laravel applications keep a normal pulse

Ensure your Laravel applications keep a normal rhythm Laravel Defibrillator helps you ensure that aspects of your application that should be running a

Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications
Zarinpal is a laravel package to easily use zarinpal.com payment services in your applications

پکیج اتصال به درگاه پرداخت زرین پال zarinpal.com برای اتصال به درگاه پرداخت اینترنتی زرین پال و استفاده از api های آن می توانید از این پکیج استفاده کن

1Pilot.io, a universal dashboard to effortlessly manage all your Laravel applications
1Pilot.io, a universal dashboard to effortlessly manage all your Laravel applications

Website · Free Trial · Pricing · Documentation · API · Feedback · Support [You] What are you, strange being? [1Pilot] Greetings, traveller. I am 1Pilo

Test your Laravel applications with phpspec

phpspec Laravel Extension phpspec extension for testing Laravel applications. Versions Depending on the version of Laravel and/or Phpspec you're using

Jumpstart your web development journey with the HALT Stack Starter Kit, a one-command solution for creating dynamic, scalable, and clean web applications.

Welcome to the HALT Stack Starter Kit! This kit is designed to help you kickstart your web development projects using the HALT Stack, a powerful combi

Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS.

Nebula Nebula is a minimalistic and easy to use administration tool for Laravel applications, made with Laravel, Alpine.js, and Tailwind CSS. Nebula m

Releases(v1.0.2)
  • v1.0.2(Sep 21, 2021)

    Add support for astrel_env

    astrel_env('my-slug');                           // Equivalent to astrel('my-slug', env('MY_SLUG'));
    astrel_env('my-slug', 'MY_ENV_SLUG');            // Equivalent to astrel('my-slug', env('MY_ENV_SLUG'));
    astrel_env('my-slug', 'MY_ENV_SLUG', 'default'); // Equivalent to astrel('my-slug', env('MY_ENV_SLUG', 'default'));
    
    Source code(tar.gz)
    Source code(zip)
  • v1.0.1(Sep 16, 2021)

    Ensure we always return an array on aspects even when the API key is wrong or missing. This ensures the get method always fallbacks to the default value in these scenarios.

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Sep 14, 2021)

  • v0.1.0(Sep 13, 2021)

Owner
Sustainable Hustle
Sustainable Hustle
Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Ogundiran Adewale Charles 2 Jul 27, 2022
Easily integrate single-database multi tenant features into your Laravel application

Laravel Tenant Aware Easily integrate single-database multi tenant features into your Laravel application. Installation You can install the package vi

H-FARM Innovation 9 Dec 21, 2022
Integrate likes, bookmarks, favorites, reactions and custom made marks into your application

Laravel Markable This package allows you to easily add the markable feature to your application, as for example likes, bookmarks, favorites and so on.

H-FARM Innovation 500 Jan 5, 2023
🧑‍🔬 The missing assertions for your views in your Laravel applications.

Laravel View Assertions The missing assertions for your views in your Laravel applications. Installation You'll have to follow a couple of simple step

Sven Luijten 4 Dec 21, 2022
An elegant package for integrate laravel with openwa

Whatsapp Laravel An elegant package to integrate Laravel with Whatsapp automate Features Function Reference Send text Send contact Send media (doc, im

Ardzz Jay Steve 7 Aug 21, 2022
An easy way to integrate Google Maps with Laravel

An easy way to integrate Google Maps with Laravel For Laravel 5.x, check version 2.35.1 For Laravel 4.x, check version 1.27.0 Think of Googlmapper as

Bradley Cornford 450 Nov 29, 2022
🖖Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any kind of filters.

Repository Repository Pattern in Laravel. The package allows to filter by request out-of-the-box, as well as to integrate customized criteria and any

Awes.io 160 Dec 26, 2022
Easy Way to integrate API in you laravel application.

Easy Api Easy Way to integrate API in you laravel application. Installation Guide Install Package using Composer. composer require flutterbuddy1/easy-

Mayank Diwakar 1 Oct 9, 2022
Ajar anak anak software looka integrate tailwind

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Aliff Rosli 2 Dec 21, 2021
Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications.

Laravel Boilerplate Project Laravel Boilerplate provides a very flexible and extensible way of building your custom Laravel applications. Table of Con

Labs64 848 Dec 28, 2022