What Files are Inside the CRUD

If you prefer a video version:

Sometimes there is a need to create a new CRUD for existing panel, even after a lot of manual code changes. How to add new CRUD's code into existing system? For that, you need to understand its structure.

Default MVC Files

When you create a CRUD, minimum of 14 new files are generated automatically - 10 new files, and 4 old ones re-generated.

There may be more changes, depending on CRUDs fields and modules involved.

For example, if you create CRUD called Transactions with a few simple columns like "amount" and "transaction_date", here's the minimum list of generated files:

[New Model]

  • app/Transaction.php

[New Controller]

  • app/Http/Controllers/Admin/TransactionsController.php

[New Form Requests]

  • app/Http/Requests/MassDestroyTransactionRequest.php

  • app/Http/Requests/StoreTransactionRequest.php

  • app/Http/Requests/UpdateTransactionRequest.php

[New database migration]

  • database/migrations/2019_12_02_000005_create_transactions_table.php

[New Blade views]

  • resources/views/admin/transactions/create.blade.php

  • resources/views/admin/transactions/edit.blade.php

  • resources/views/admin/transactions/index.blade.php

  • resources/views/admin/transactions/show.blade.php

[Changed main menu Blade view]

  • resources/views/partials/menu.blade.php

[Changed main routes]

  • routes/web.php

[Changed Seeds for Permissions]

  • database/seeds/PermissionsTableSeeder.php

[Changed Translation Files for new CRUD]

  • resources/lang/en/cruds.php

Database Migrations: Important Notice

After every new or changed CRUD, we regenerate all migration files to make sure they are in the right order, to avoid creating foreign keys on non-existing tables. Therefore, keep in mind that you need to double-check the migration files manually, so they still work after you merge changes.

Additional Files - Depending on Parameters

A few more files may change with each new CRUD.

For example, if you add a belongsTo relationship column to other CRUD like Users, then additional these files are touched:

  • [Changed] app/User.php

  • [New] database/migrations/2019_12_02_relationships_transactions_table.php

If you ticked the checkbox to generate API, another list of new files:

  • [New] app/Http/Controllers/Api/V1/Admin/TransactionsApiController.php

  • [New] app/Http/Resources/Admin/TransactionResource.php

  • [Changed] routes/api.php

And the list may be bigger, with additional field types or modules. But, in short, these are the minimum files you need to download and copy-paste or merge into your existing project code.

Practical Example

If you want to view content of those files, here is an example Github Pull Request of changed files for one new CRUD, similar to the above example.

Last updated