Package helper for Wordpress integration into your Laravel project using direct DB, GraphQL or Rest integration

1.2.3 2022-09-15 20:36 UTC

This package is not auto-updated.

Last update: 2022-12-08 21:52:14 UTC


Build Status Scrutinizer Code Quality

Packagist Packagist Packagist

Laravel helper for Wordpress integration into your project. It's a wrapper to implement 3 solutions : using direct database connection (using Corcel), using the RestAPI (using WP-Json) and using GraphQL Wordpress Plugin.

Why having 3 solutions and not using only one ?

Corcel access directly to the WP Database to make queries that grant definitely a better db access for quering post but it doesn't render any native wordpress scripts/hooks like Gutenberg rendering or plugins filters see issue.

The strategy for that is to use the WpGraphQL Api (strongly typed) or Wp Rest Api (weakly typed) to allow special rendering through the Wordpress so you can have benefits from these 3 solutions in your Laravel Project.


Install via composer

composer require cherrypulp/laravel-wordpress

Register Service Provider

Note! This and next step are optional if you use laravel>=5.5 with package auto discovery feature.

Add service provider to config/app.php in providers section


Register Facade

Register package facade in config/app.php in aliases section


Publish Configuration File

php artisan vendor:publish --provider="Cherrypulp\LaravelWordpress\ServiceProvider" --tag="config"

Setup the database

To make it work, you must set the database connection to your Wordpress and add

Then in your .env file you must define :


# Important if you want to have access to protected endpoint
WP_API_TOKEN="http://xxxx/wp-json/" #Api Token @see on how to generate that
WP_API_TYPE="BEARER" #The type of Authentication used @see : for more information (default is Bearer Oauth type)


This package is a Wrapper for Laravel Corcel and Wordpress GraphQL allowing direct connection to Wordpress.

Please check the documentation for more information, and for more infos.

GraphQL Based query

GraphQL client is based on our package :

You can basically make just a query like that :

$posts = lwp()->graphql()->query($graphqlQuery, $params);


$post = lwp()->getPostBySlug('hello-world');

Return the post by is slug

Available methods

$home = lwp()->getHome();

# Return the homepage information

$post = lwp()->getPostBySlug('hello-world');

$posts = lwp()->getHighlightedPosts();

# Get the posts marked as featured posts

$category = lwp()->getCategoryBySlug('essential');


# Flush all cached queries

Using REST Api

You can access through :

$posts = lwp()->http()->get('wp/v2/posts');

Under the hood it's just a wrapper on top of HTTP client of Laravel :

Using Corcel models

Corcel models are accessible through lwp()->{$modelName} variable.

Exemple : the model Post is accessible through lwp()->post->slug('hello-world');

For more infos, see :

Getting deeper

How to override GraphQL query ?

You can override default GraphQL query by simply copy-paste the graphql/query.ql in the folder of this plugin into your graphql folder. You can also override the config inside config/laravel-wordpress.php

How to extends the repository ?

You can replace the default WordpressRepository by changing the config/laravel-wordpress :


"repository" => MyOwnWordpressRepository::class,


Then you are free to implement your own class but be sure to implements the WordpressRepositoryContract interface.

use Cherrypulp\LaravelWordpress\Repositories;
use Cherrypulp\LaravelWordpress\Repositories\WordpressRepositoryContract;

class MyOwnWordpressRepository extends WordpressRepository implements WordpressRepositoryContract {



If you discover any security related issues, please email instead of using the issue tracker.


This package is bootstrapped with the help of cherrypulp/laravel-package-generator.