Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon What are the steps to use Blueprint with an existing Laravel project
    Laravel Shift Blueprint Laravel integration migrations YAML schema Artisan commands Blueprint tutorial


What are the steps to use Blueprint with an existing Laravel project


To use Laravel Shift Blueprint with an existing Laravel project, follow these steps:

1. Install Blueprint as a development dependency using Composer:


composer require -W --dev laravel-shift/blueprint

2. Define your existing database schema in a YAML-based "draft" file. For example, create a file named `draft.yaml` in your project's root directory with the following content:

yaml
models:
  User:
    username: string:128
    email: string:255
    password: string:255
    first_name: string:45
    last_name: string:45
    timezone: string:45
    location_id: id:location
    deleted_at: timestamp
    remember_token: string:255

This defines a `User` model with the specified columns and types[1][2].

3. Run the `blueprint:build` Artisan command to generate the migrations:


php artisan blueprint:build draft.yaml

This will generate a migration file that matches the defined schema, including the table structure, columns, indexes, and foreign key constraints[1][4].

4. Run the migrations to create the database tables:


php artisan migrate

5. (Optional) Generate additional components like controllers, form requests, factories, etc. by updating the `draft.yaml` file. For example, add a `Post` model and a `PostController` to the draft:

yaml
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

6. Run `blueprint:build` again to generate the new components:


php artisan blueprint:build draft.yaml

This will generate the `Post` model, migration, controller, form request, and related components[1][2].

By following these steps, you can easily integrate Blueprint into an existing Laravel project to rapidly generate migrations and other components based on your application's schema and requirements.

Citations:
[1] https://github.com/laravel-shift/blueprint
[2] https://laravel-news.com/laravel-shift-blueprint
[3] https://blueprint.laravelshift.com
[4] https://blueprint.laravelshift.com/docs/installation/
[5] https://laracasts.com/discuss/channels/laravel/blueprint-laravel-shift