PHPackages                             scrnhq/laravel-bakery - 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. [API Development](/categories/api)
4. /
5. scrnhq/laravel-bakery

ActiveLibrary[API Development](/categories/api)

scrnhq/laravel-bakery
=====================

An on-the-fly GraphQL Schema generator from Eloquent models for Laravel.

v3.3.11(4y ago)10418.2k9[12 issues](https://github.com/scrnhq/laravel-bakery/issues)[3 PRs](https://github.com/scrnhq/laravel-bakery/pulls)MITPHPPHP ^7.2|^8.0

Since Jun 10Pushed 4y ago6 watchersCompare

[ Source](https://github.com/scrnhq/laravel-bakery)[ Packagist](https://packagist.org/packages/scrnhq/laravel-bakery)[ RSS](/packages/scrnhq-laravel-bakery/feed)WikiDiscussions 3.x Synced yesterday

READMEChangelog (10)Dependencies (8)Versions (54)Used By (0)

 [![Laravel Bakery logo](./artwork.svg)](./artwork.svg)

 [![Build Status status](https://github.com/scrnhq/laravel-bakery/workflows/CI/badge.svg)](https://github.com/scrnhq/laravel-bakery/actions) [![Latest Version](https://camo.githubusercontent.com/533dc45d3898c74221f4bf9d42500af084a2eaa3b75e4a01ed00b6587f45cd20/68747470733a2f2f706f7365722e707567782e6f72672f7363726e68712f6c61726176656c2d62616b6572792f76657273696f6e)](https://packagist.org/packages/scrnhq/laravel-bakery) [![Code Quality](https://camo.githubusercontent.com/e768870a188be38dae092180241af61e12feb431543c641dd28d3f6e82cdd779/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7363726e68712f6c61726176656c2d62616b6572792e737667)](https://scrutinizer-ci.com/g/scrnhq/laravel-bakery) [![Total Downloads](https://camo.githubusercontent.com/9a16d76606ae46e50be507f8096b86025908756022b44353cbbb476abbf2dcef/68747470733a2f2f706f7365722e707567782e6f72672f7363726e68712f6c61726176656c2d62616b6572792f646f776e6c6f616473)](https://packagist.org/packages/scrnhq/laravel-bakery) [![License](https://camo.githubusercontent.com/ea15b91aa3790fec228d065f560668cd33337ef69fab3860fa3a1e76a7852ee8/68747470733a2f2f706f7365722e707567782e6f72672f7363726e68712f6c61726176656c2d62616b6572792f6c6963656e73652e737667)](https://packagist.org/packages/scrnhq/laravel-bakery)

---

An on-the-fly GraphQL Schema generator from Eloquent models for Laravel.

- [Installation](#installation)
- [Quickstart](#quickstart)
- [Model schemas](#model-schemas)

Installation
------------

[](#installation)

This package requires PHP 7.2 and Laravel 6 or higher. To get started with Bakery, simply run:

```
composer require scrnhq/laravel-bakery

```

Quickstart
----------

[](#quickstart)

After installing Bakery, publish the configuration and asserts using the `bakery:install` Artisan command.

```
php artisan bakery:install

```

After running this command, the configuration file should be located at `config/bakery.php`. The default `App\Bakery\User` Bakery model schema refers to the `App\User` model.

You can find your new GraphQL API at `/graphql` and you can navigate to `/graphql/explore` to find GraphiQL, the graphical interactive GraphQL IDE.

```
query {
  users {
    items {
      id
    }
  }
}
```

Model schemas
-------------

[](#model-schemas)

Model schemas are classes that lets you connect your Eloquent models with the GraphQL API. In there you can define which fields are available, which of them can be mutated and much more.

By default, Bakery model schema's are stored in the `app\Bakery` directory. You can generate a new model schema using the handy `bakery:modelschema` Artisan command.

```
php artisan bakery:modelschema Post

```

The `model` property of a model schema defines which Eloquent model it corresponds to.

```
/**
 * The model the schema corresponds to.
 *
 * @var string
 */
protected $model = \App\Post::class;
```

### Registering model schemas

[](#registering-model-schemas)

> All model schema's in the `app/Bakery` directory will automatically be registered by Bakery. If you choose to store your model schema's differently, you need to define and register your schema manually.

**You are not required to manually define and register a Schema. You can skip this step if you do not wish to manually register a schema.**

In order to make model schemas available within GraphQL, they must be registered in a Schema. First you must create a new `Schema` class. Next, you should set the `schema` item in the `config/bakery.php` file to the newly created Schema.

There are two ways to manually registering model schemas in Bakery. You can use the `modelsIn` method in the schema to load all models schemas in a given directory, or you can manually return an array of models schemas.

```
namespace App\Support;

use Bakery\Support\Schema as BaseSchema;

class Schema extends BaseSchema
{
    /*
     * Get the models for the schema.
     *
     * @return array
     */
    public function models()
    {
        return $this->modelsIn(app_path('Bakery'));

        // Or, manually.
        return [
            App\Bakery\User::class,
            App\Bakery\Post::class,
        ];
    }
}
```

Now that you have created and registered your model schemas with Bakery, you can browse to `/graphql/explore` and query your models in the interactive playground GraphQL.

```
query {
  posts {
    items {
      id
    }
  }
}
```

If everything is set up properly you will get a collection of posts in your database. You can also use GraphQL to retrieve a single post.

```
query {
  posts(id: "1") {
    id
  }
}
```

Just like Laravel, Bakery follows naming conventions. It uses Laravel's pluralization library to transform your model into queries so you can fetch an individual Post with `post` and a collection of Posts with `posts`.

### Fields

[](#fields)

Now, each Bakery model schema contains a `fields` that return an array of fields, which extend the `\Bakery\Fields\Field` class. To add a field to model schema, simply add it to `fields` method, where the key of the item must match the name of the model `attribute`.

```
use Bakery\Field;

/**
 * Get the fields for the schema.
 *
 * @return array
 */
public function fields(): array
{
    return [
        'title' => Field::string(),
    ];
}
```

Now you can query the title of the posts in GraphQL.

```
query {
  post(id: "1") {
    id
    title
  }
}
```

#### Field Types

[](#field-types)

Bakery has the following fields available:

- [Boolean](#boolean)
- [Float](#float)
- [ID](#id)
- [Int](#int)
- [String](#string)

##### Boolean

[](#boolean)

```
Field::boolean()
```

##### Float

[](#float)

```
Field::float()
```

##### ID

[](#id)

```
Field::ID()
```

##### Int

[](#int)

```
Field::int()
```

##### String

[](#string)

```
Field::string()
```

### Relations

[](#relations)

In addition to the fields described above, Bakery supports Eloquent relationships, too. To add a relationship to the model schema, simply add it to the `relations` method, where the key of the item must match the relation name. Let's say a `User` model `hasMany` `Post` models. Then you would define your Bakery model schema's like so:

`app\Bakery\User.php`

```
use Bakery\Field;
use App\Bakery\Post;

/**
 * Get the fields for the schema.
 *
 * @return array
 */
public function relations()
{
    return [
        'posts' => Field::collection(Post::class),
    ];
}
```

The inverse of the previous relation is that a `Post` model `belongsTo` a `User` model. The Bakery model schema would be defined like so:

`app\Bakery\Post.php`

```
use Bakery\Field;
use App\Bakery\User;

/**
 * Get the fields for the schema.
 *
 * @return array
 */
public function relations()
{
    return [
        'user' => Field::model(User::class),
    ];
}
```

This way you can get all posts related to a user within a single GraphQL query.

```
query {
  user(id: "1") {
    id
    posts {
      id
    }
  }
}
```

### Mutations

[](#mutations)

Another key feature of GraphQL that Bakery fully supports are mutations. Bakery automatically creates the `create`, `update`, and `delete` mutations for each registered model. Bakery also seamlessly uses Laravel's policies to authorize the actions of your users.

> Having policies for your models is required for Bakery mutations to work. See  for more information.

For example, with the model schemas mentioned above, you could create a `Post` with a simple GraphQL mutation.

```
mutation {
  createPost(input: {
    title: "Hello world!"
  }) {
    id
  }
}
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

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 ~27 days

Recently: every ~76 days

Total

48

Last Release

1610d ago

Major Versions

1.x-dev → v2.0.0-beta.12018-08-21

v2.1.10 → v3.0.02019-09-06

PHP version history (6 changes)v1.0.0PHP ^7.0

v2.0.0-beta.1PHP ^7.1

v2.0.0PHP &gt;=7.1.0

v3.0.0PHP ^7.1.3

v3.3.5PHP ^7.2

v3.3.6PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/de7b0560fc6f16a90b64b73f125ab92331171f08d22a1569972ead0341eb9c01?d=identicon)[erikgaal](/maintainers/erikgaal)

![](https://www.gravatar.com/avatar/9832602d5b04f09fa5bd162acbaf87b0e5c50ce9a96b970424e78a3830695eb1?d=identicon)[robertvansteen](/maintainers/robertvansteen)

---

Tags

apigraphqllaravelpackagephplaravelgraphql

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/scrnhq-laravel-bakery/health.svg)

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

###  Alternatives

[nuwave/lighthouse

A framework for serving GraphQL from Laravel

3.5k10.7M93](/packages/nuwave-lighthouse)[rebing/graphql-laravel

Laravel wrapper for PHP GraphQL

2.2k7.1M26](/packages/rebing-graphql-laravel)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[thecodingmachine/graphqlite-laravel

A Laravel service provider package to help you get started with GraphQLite in Laravel.

1852.3k1](/packages/thecodingmachine-graphqlite-laravel)

PHPackages © 2026

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