{"id":13563902,"url":"https://github.com/scrnhq/laravel-bakery","last_synced_at":"2026-01-14T01:14:56.632Z","repository":{"id":51361732,"uuid":"109427894","full_name":"scrnhq/laravel-bakery","owner":"scrnhq","description":"🍞🧑‍🍳 An on-the-fly GraphQL Schema generator from Eloquent models for Laravel.","archived":false,"fork":false,"pushed_at":"2021-12-14T11:41:01.000Z","size":1040,"stargazers_count":104,"open_issues_count":12,"forks_count":9,"subscribers_count":6,"default_branch":"3.x","last_synced_at":"2025-12-21T07:18:56.943Z","etag":null,"topics":["api","graphql","laravel","package","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scrnhq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2017-11-03T18:07:39.000Z","updated_at":"2025-10-27T11:18:45.000Z","dependencies_parsed_at":"2022-09-11T14:40:11.292Z","dependency_job_id":null,"html_url":"https://github.com/scrnhq/laravel-bakery","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/scrnhq/laravel-bakery","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrnhq%2Flaravel-bakery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrnhq%2Flaravel-bakery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrnhq%2Flaravel-bakery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrnhq%2Flaravel-bakery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scrnhq","download_url":"https://codeload.github.com/scrnhq/laravel-bakery/tar.gz/refs/heads/3.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scrnhq%2Flaravel-bakery/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28407661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T00:40:43.272Z","status":"ssl_error","status_checked_at":"2026-01-14T00:40:42.636Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","graphql","laravel","package","php"],"created_at":"2024-08-01T13:01:24.420Z","updated_at":"2026-01-14T01:14:56.615Z","avatar_url":"https://github.com/scrnhq.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./artwork.svg\" alt=\"Laravel Bakery logo\" width=\"300\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/scrnhq/laravel-bakery/actions\"\u003e\u003cimg src=\"https://github.com/scrnhq/laravel-bakery/workflows/CI/badge.svg\" alt=\"Build Status status\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/scrnhq/laravel-bakery\"\u003e\u003cimg src=\"https://poser.pugx.org/scrnhq/laravel-bakery/version\" alt=\"Latest Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://scrutinizer-ci.com/g/scrnhq/laravel-bakery\"\u003e\u003cimg src=\"https://img.shields.io/scrutinizer/g/scrnhq/laravel-bakery.svg\" alt=\"Code Quality\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/scrnhq/laravel-bakery\"\u003e\u003cimg src=\"https://poser.pugx.org/scrnhq/laravel-bakery/downloads\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://packagist.org/packages/scrnhq/laravel-bakery\"\u003e\u003cimg src=\"https://poser.pugx.org/scrnhq/laravel-bakery/license.svg\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n-----\n\nAn on-the-fly GraphQL Schema generator from Eloquent models for Laravel.\n\n- [Installation](#installation)\n- [Quickstart](#quickstart)\n- [Model schemas](#model-schemas)\n\n## Installation\n\nThis package requires PHP 7.2 and Laravel 6 or higher. To get started with Bakery, simply run:\n\n```\ncomposer require scrnhq/laravel-bakery\n```\n\n## Quickstart\n\nAfter installing Bakery, publish the configuration and asserts using the `bakery:install` Artisan command.\n\n```\nphp artisan bakery:install\n```\n\nAfter running this command, the configuration file should be located at `config/bakery.php`. The default\n`App\\Bakery\\User` Bakery model schema refers to the `App\\User` model.\n\nYou can find your new GraphQL API at `/graphql` and you can navigate to `/graphql/explore` to find GraphiQL, the\ngraphical interactive GraphQL IDE.\n\n```gql\nquery {\n  users {\n    items {\n      id\n    }\n  }\n}\n```\n\n## Model schemas\n\nModel 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.\n\nBy default, Bakery model schema's are stored in the `app\\Bakery` directory. You can generate a new model schema using\nthe handy `bakery:modelschema` Artisan command.\n\n```\nphp artisan bakery:modelschema Post\n```\n\nThe `model` property of a model schema defines which Eloquent model it corresponds to.\n\n```php\n/**\n * The model the schema corresponds to.\n *\n * @var string\n */\nprotected $model = \\App\\Post::class;\n```\n\n### Registering model schemas\n\n\u003e All model schema's in the `app/Bakery` directory will automatically be registered by Bakery. If you choose to \n\u003e store your model schema's differently, you need to define and register your schema manually.\n\n**You are not required to manually define and register a Schema. You can skip this step if you do not wish to\nmanually register a schema.**\n\nIn order to make model schemas available within GraphQL, they must be registered in a Schema. First you must create\na new `Schema` class. Next, you should set the `schema` item in the `config/bakery.php` file to the newly created\nSchema.\n\nThere are two ways to manually registering model schemas in Bakery. You can use the `modelsIn` method in the schema\nto load all models schemas in a given directory, or you can manually return an array of models schemas.\n \n```php\nnamespace App\\Support;\n\nuse Bakery\\Support\\Schema as BaseSchema;\n\nclass Schema extends BaseSchema\n{\n    /*\n     * Get the models for the schema.\n     *\n     * @return array\n     */\n    public function models()\n    {\n        return $this-\u003emodelsIn(app_path('Bakery'));\n        \n        // Or, manually.\n        return [\n            App\\Bakery\\User::class,\n            App\\Bakery\\Post::class,\n        ];\n    }\n}\n```\n\nNow that you have created and registered your model schemas with Bakery, you can browse to `/graphql/explore` and query\nyour models in the interactive playground GraphQL.\n\n```gql\nquery {\n  posts {\n    items {\n      id\n    }\n  }\n}\n```\n\nIf everything is set up properly you will get a collection of posts in your database. You can also use GraphQL to\nretrieve a single post.\n\n```gql\nquery {\n  posts(id: \"1\") {\n    id\n  }\n}\n```\n\nJust like Laravel, Bakery follows naming conventions. It uses Laravel's pluralization library to transform your model\ninto queries so you can fetch an individual Post with `post` and a collection of Posts with `posts`.\n\n### Fields\n\nNow, each Bakery model schema contains a `fields` that return an array of fields, which extend the\n`\\Bakery\\Fields\\Field` class. To add a field to model schema, simply add it to `fields` method, where the key of\nthe item must match the name of the model `attribute`.\n\n```php\nuse Bakery\\Field;\n\n/**\n * Get the fields for the schema.\n *\n * @return array\n */\npublic function fields(): array\n{\n    return [\n        'title' =\u003e Field::string(),\n    ];\n}\n```\n\nNow you can query the title of the posts in GraphQL.\n\n```gql\nquery {\n  post(id: \"1\") {\n    id\n    title\n  }\n}\n```\n\n#### Field Types\n\nBakery has the following fields available:\n\n- [Boolean](#boolean)\n- [Float](#float)\n- [ID](#id)\n- [Int](#int)\n- [String](#string)\n\n##### Boolean\n```php\nField::boolean()\n```\n\n##### Float\n```php\nField::float()\n```\n\n##### ID\n```php\nField::ID()\n```\n\n##### Int\n```php\nField::int()\n```\n\n##### String\n```php\nField::string()\n```\n\n### Relations\n\nIn addition to the fields described above, Bakery supports Eloquent relationships, too. To add a relationship to the\nmodel schema, simply add it to the `relations` method, where the key of the item must match the relation name. Let's\nsay a `User` model `hasMany` `Post` models. Then you would define your Bakery model schema's like so:\n\n`app\\Bakery\\User.php`\n\n```php\nuse Bakery\\Field;\nuse App\\Bakery\\Post;\n\n/**\n * Get the fields for the schema.\n *\n * @return array\n */\npublic function relations()\n{\n    return [\n        'posts' =\u003e Field::collection(Post::class),\n    ];\n}\n```\n\nThe inverse of the previous relation is that a `Post` model `belongsTo` a `User` model. The Bakery model schema\nwould be defined like so:\n\n`app\\Bakery\\Post.php`\n\n```php\nuse Bakery\\Field;\nuse App\\Bakery\\User;\n\n/**\n * Get the fields for the schema.\n *\n * @return array\n */\npublic function relations()\n{\n    return [\n        'user' =\u003e Field::model(User::class),\n    ];\n}\n```\n\nThis way you can get all posts related to a user within a single GraphQL query.\n\n```gql\nquery {\n  user(id: \"1\") {\n    id\n    posts {\n      id\n    }\n  }\n}\n```\n\n### Mutations\n\nAnother key feature of GraphQL that Bakery fully supports are mutations. Bakery automatically creates the `create`,\n`update`, and `delete` mutations for each registered model. Bakery also seamlessly uses Laravel's policies to\nauthorize the actions of your users.\n\n\u003e Having policies for your models is required for Bakery mutations to work. See \n\u003e https://laravel.com/docs/5.7/authorization for more information.\n\nFor example, with the model schemas mentioned above, you could create a `Post` with a simple GraphQL mutation.\n\n```gql\nmutation {\n  createPost(input: {\n    title: \"Hello world!\"\n  }) {\n    id\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrnhq%2Flaravel-bakery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscrnhq%2Flaravel-bakery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscrnhq%2Flaravel-bakery/lists"}