PHPackages                             momentohq/laravel-example - 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. [Caching](/categories/caching)
4. /
5. momentohq/laravel-example

ActiveProject[Caching](/categories/caching)

momentohq/laravel-example
=========================

The Laravel weather app to showcase Momento cache driver.

v0.3.2(2y ago)166Apache-2.0PHPPHP ^8.0.2

Since Nov 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/momentohq/laravel-example)[ Packagist](https://packagist.org/packages/momentohq/laravel-example)[ RSS](/packages/momentohq-laravel-example/feed)WikiDiscussions main Synced yesterday

READMEChangelog (8)Dependencies (2)Versions (22)Used By (0)

[![logo](https://camo.githubusercontent.com/360a9d3e7faa618e55deff1ab31e825f62c35ef7fe7e295751a90634d235549a/68747470733a2f2f646f63732e6d6f6d656e746f68712e636f6d2f696d672f6d6f6d656e746f2d6c6f676f2d666f726573742e737667)](https://camo.githubusercontent.com/360a9d3e7faa618e55deff1ab31e825f62c35ef7fe7e295751a90634d235549a/68747470733a2f2f646f63732e6d6f6d656e746f68712e636f6d2f696d672f6d6f6d656e746f2d6c6f676f2d666f726573742e737667)

Momento Laravel Example
=======================

[](#momento-laravel-example)

In this repo, you will see an example of how to integrate a Momento cache into your Laravel app, instead of a Redis or Memcached. What's the benefits, you ask? You don't have to worry about Redis/Memcached nodes! Intrigued? Keep on reading!

Run the app via Docker
----------------------

[](#run-the-app-via-docker)

Before building a Docker image, create `.env` file in `docker` directory with the following env variables:

- `MOMENTO_API_KEY`=&lt;YOUR\_API\_KEY&gt;
- `MOMENTO_CACHE_NAME`=&lt;YOUR\_CACHE\_NAME&gt;
- `WEATHER_API_KEY` this is for weather API. Check out [OpenWeather](https://openweathermap.org/) to get an API key.

If you don't have a Momento API key, you can generate one using the [Momento Console](https://console.gomomento.com).

Build a Docker image for the app:

```
cd docker
docker build --tag laravel-example .
```

**Note**: Building the `laravel-example` image involves compiling the PHP gRPC extension, which will take several minutes to complete.

If you run into the API limits from GitHub, add a GitHub personal access token to your composer configuration:

```
export COMPOSER_AUTH=
docker build --tag laravel-example --build-arg COMPOSER_AUTH=$COMPOSER_AUTH .
```

And run a Docker container with the image:

```
docker run -d --env-file .env -p 8000:8000 laravel-example
```

Manual PHP Setup
----------------

[](#manual-php-setup)

You will need to install the following:

- [PHP](https://www.php.net/manual/en/install.php)
- [Composer](https://getcomposer.org/doc/00-intro.md)
- [Laravel](https://laravel.com/docs/10.x/installation)
- [gRPC for PHP](https://cloud.google.com/php/grpc)

Add the repository and dependency to your project's `composer.json`:

```
{
  "require": {
    "momentohq/laravel-example": "0.2.3"
  }
}
```

Add the Momento configuration to the 'stores' section of `config/cache.php`, adjusting the `cache_name` and `default_ttl` parameters as needed:

```
'stores' => [
        ...
        'momento' => [
            'driver' => 'momento',
            'cache_name' => 'my-momento-cache',
            'default_ttl' => 60,
        ],
],
```

Update the cache driver entry in your `.env` file:

`CACHE_DRIVER=momento`

And add the following environment variables into your `.env` file:

- `WEATHER_API_KEY` this is for weather API. Check out [OpenWeather](https://openweathermap.org/) to get an API key.
- `MOMENTO_API_KEY`

If you don't have a Momento API key, you can generate one using the [Momento Console](https://console.gomomento.com).

Run `composer update` to install the necessary prerequisites.

To run this application:

```
php artisan serve
```

cURL commands
-------------

[](#curl-commands)

```
curl http://127.0.0.1:8000/api/weather/

Example:
curl http://127.0.0.1:8000/api/weather/denver
```

or

```
curl http://127.0.0.1:8000/api/weather//

Example:
curl http://127.0.0.1:8000/api/weather/98101/us
```

or

```
curl http://127.0.0.1:8000/api/weather/id/

City id can be found here: http://bulk.openweathermap.org/sample/

Example:
curl http://127.0.0.1:8000/api/weather/id/833
```

Exploring the Momento Cache Integration
---------------------------------------

[](#exploring-the-momento-cache-integration)

Examples of different ways to use Momento's Laravel cache client and cache driver can be found in the [WeatherController.php](src/Controllers/WeatherController.php).

For examples of using the Momento client directly, check out our PHP SDK [examples](https://github.com/momentohq/client-sdk-php/tree/main/examples)!

A simple example usage of Momento's Laravel cache driver is extracted below:

```
$apiKey = env("WEATHER_API_KEY");
$url = "https://api.openweathermap.org/data/2.5/weather?q={$city}&appid={$apiKey}";
$result = Cache::get($city);
if (!is_null($result)) {
    return $result;
} else {
    $res = $this->httpClient->get($url);
    if ($res->getStatusCode() == 200) {
        $json = $res->getBody();
        // 10 minutes TTLc
        Cache::put($city, $json, 600);
        return $json;
    }
}
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 68.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~72 days

Recently: every ~91 days

Total

8

Last Release

829d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44378720?v=4)[momento](/maintainers/momento)[@momento](https://github.com/momento)

---

Top Contributors

[![poppoerika](https://avatars.githubusercontent.com/u/22686260?v=4)](https://github.com/poppoerika "poppoerika (32 commits)")[![pgautier404](https://avatars.githubusercontent.com/u/5394199?v=4)](https://github.com/pgautier404 "pgautier404 (12 commits)")[![rishtigupta](https://avatars.githubusercontent.com/u/127137312?v=4)](https://github.com/rishtigupta "rishtigupta (2 commits)")[![anitarua](https://avatars.githubusercontent.com/u/138700973?v=4)](https://github.com/anitarua "anitarua (1 commits)")

---

Tags

laravelcacheserverless

### Embed Badge

![Health badge](/badges/momentohq-laravel-example/health.svg)

```
[![Health](https://phpackages.com/badges/momentohq-laravel-example/health.svg)](https://phpackages.com/packages/momentohq-laravel-example)
```

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[svix/svix

Svix PHP Library

3.3k964.7k8](/packages/svix-svix)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[yediyuz/laravel-cloudflare-cache

laravel-cloudflare-cache

28445.4k](/packages/yediyuz-laravel-cloudflare-cache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
