> This page is for Contentful SDKs.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://contentful-staging.ferndocs.com/developers/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://contentful-staging.ferndocs.com/developers/docs/_mcp/server.

# Getting started with Contentful and Laravel

> This tutorial will show you how to setup the Content Delivery API in your Laravel application and how to access your content inside the framework.

This Laravel CMS tutorial will show you how to setup the Content Delivery API in your Laravel application and how to access your content
inside the framework.

## Requirements

The Contentful Laravel integration requires at least PHP 7.0.

## Installation

The easiest way to install the Laravel integration is is to use [Composer](https://getcomposer.org).

```bash
composer require contentful/laravel
```

### Enable the Service Provider

Next you need to enable the Service Provider by adding it to `config/app.php`:

```php
return [
    'providers' => [
        // ...
        Contentful\Laravel\ContentfulServiceProvider::class,
        // ...
    ]
];
```

### Configuration

Before the PHP client library can be configured, the necessary config files have to be published. To do so execute the following command:

```bash
php artisan vendor:publish  --provider="Contentful\Laravel\ContentfulServiceProvider"
```

This will add a file called `contentful.php` to your `/config` folder. Now open it, and add *at least* your space ID and API key.

```php
return [
    /*
     * The ID of the space you want to access.
     */
    'delivery.space' => env('CONTENTFUL_SPACE_ID'),
    /*
     * The ID of the environment you want to access.
     */
    'delivery.environment' => env('CONTENTFUL_ENVIRONMENT_ID', 'master'),
    /*
     * An API key for the above specified space.
     */
    'delivery.token' => env('CONTENTFUL_DELIVERY_TOKEN'),
    /*
     * Controls whether Contentful's Delivery or Preview API is accessed.
     */
    'delivery.preview' => (bool) env('CONTENTFUL_USE_PREVIEW', \false),
    /*
     * The default locale to use when querying the API.
     */
    'delivery.defaultLocale' => env('CONTENTFUL_DEFAULT_LOCALE'),
    /*
     * A closure which manipulates a ClientOptions object.
     * See Contentful\Delivery\ClientOptions for more.
     */
    'delivery.options' => function (ClientOptions $options, Application $application) {
        // Update $options however you prefer
    },
];
```

## Using Contentful

You now have a service for the class `Contentful\Delivery\Client` available. A small controller displaying an entry based on an ID in the URL could look like this:

```php
use Illuminate\Routing\Controller as BaseController;
use Contentful\Delivery\Client as DeliveryClient;

class DefaultController extends Controller
{
    /**
     * @var DeliveryClient
     */
    private $client;

    public function __construct(DeliveryClient $client)
    {
        $this->client = $client;
    }

    public function entryAction($id)
    {
        $entry = $this->client->getEntry($id);

        if (!$entry) {
            abort(404);
        }

        return view('entry', [
            'entry' => $entry
        ]);
    }
}
```

To discover how to use the Contentful client, check out the [getting started with Contentful and PHP](/sdks/php/tutorials/getting-started-with-contentful-and-php) tutorial.

## Conclusion

Now you should be familiar with the basics of how to use Contentful in a Laravel application. You can find the integration on [GitHub](https://github.com/contentful/contentful-laravel/) and [Packagist](https://packagist.org/packages/contentful/laravel). To get a deeper understanding, read some of our other [PHP tutorials](/sdks/php/client-libraries#tutorials). If you find a bug, or have an idea how to further integrate with Laravel, please open an [issue on GitHub](https://github.com/contentful/contentful-laravel/issues).