Laravel Shift Blueprint

repository·master·Indexed 25 days ago

https://github.com/laravel-shift/blueprint

An open-source tool for rapidly generating Laravel components—including models, migrations, controllers, routes, form requests, mailables, jobs, events, Blade templates, and tests—from a single human-readable YAML definition. Requires Laravel 11 or higher for current versions. Includes Artisan commands such as blueprint:build, blueprint:init, blueprint:new, blueprint:erase, and blueprint:trace.

Tokens
1.9K
Snippets
4
Records
22
Agent score
83%

What's inside Blueprint

  1. Blueprint requirements and version support

    master
    Blueprint requires a Laravel application running Laravel 11 or higher. Starting with version 2, Blueprint only generates code for supported versions of Laravel. If you need to support older versions, you may need to constrain Blueprint to an older version or upgrade your application.
  2. Upgrade Blueprint for Laravel 11 support

    master

    To use Laravel 11 conventions (modern structure, PHP attributes, and model methods), upgrade to Blueprint version 2.13.

    Note: Version 2.13 drops support for Laravel 10. If you are still running Laravel 10, you must constrain your Blueprint version to 2.12.0.

  3. Upgrade Blueprint for Laravel 10 support

    master

    To use Laravel 10 conventions (notably type-hints in code), upgrade to Blueprint version 2.6.

    Note: Version 2.6 drops support for Laravel 9. If you are still running Laravel 9, you must constrain your Blueprint version to 2.5.0.

  4. Install Additional Assertions for Blueprint tests

    master

    If you intend to run the tests generated by Blueprint, you must also install the jasonmccreary/laravel-test-assertions package as a development dependency.

    composer require --dev jasonmccreary/laravel-test-assertions
  5. Publish Blueprint configuration and stubs

    master

    You can publish the Blueprint configuration file and the default stubs to your application using the following Artisan commands:

    To publish the configuration file: php artisan vendor:publish --tag=blueprint-config

    To publish the default stubs to your application's stubs/blueprint directory: php artisan vendor:publish --tag=blueprint-stubs

  6. Define Laravel components using a YAML draft file

    master

    Blueprint uses a human-readable YAML file (typically named draft.yaml) to define models and controllers. From a single definition, Blueprint can generate models, migrations, factories, controllers, routes, form requests, mailables, jobs, events, Blade templates, and tests.

    models:
      Post:
        title: string:400
        content: longtext
        published_at: nullable timestamp
        author_id: id:user
    
    controllers:
      Post:
        index:
          query: all
          render: post.index with:posts
    
        store:
          validate: title, content, author_id
          save: post
          send: ReviewPost to:post.author.email with:post
          dispatch: SyncMedia with:post
          fire: NewPost with:post
          flash: post.title
          redirect: posts.index
  7. Configure Policy and Model namespaces

    master

    Blueprint uses configuration keys to determine the base namespaces for generated Policies and Models. These settings allow you to customize where your authorization logic and data models reside within your application structure.

    • blueprint.namespace: The base application namespace.
    • blueprint.policy_namespace: An optional sub-namespace for Policies (e.g., Policies).
    • blueprint.models_namespace: An optional sub-namespace for Models (e.g., Models).
  8. Configuration changes in Blueprint 2.x

    master

    When upgrading to version 2.x, note the following changes to configuration options to align with Laravel 8 conventions:

    • models_namespace: The default value is now Models.
    • generate_fqcn_route: This option was removed. Blueprint now generates all routes using fully qualified class names and tuples by default.
  9. Generate Laravel components with blueprint:build

    master

    Use the blueprint:build Artisan command to process your draft definition file and generate the corresponding Laravel components (models, migrations, controllers, routes, etc.).

    php artisan blueprint:build