Getting Started
A typical admin feature repeats the same structure for every entity: an ORM entity, a migration, a repository, a controller, a list view, an edit form, and routes. Writing these by hand takes time and invites small inconsistencies. Unicorn's generator creates all of them in a few commands, so you can start from a working list and editor and focus on the business rules.
Prerequisites
Install Unicorn and configure a database first. See Installation.
Complete Example
Generate the admin CRUD for a Product entity, apply its migration, and start the local server:
php windwalker g unicorn:mvc-admin Admin/Product
php windwalker mig:go
php windwalker server:start php:main --host localhost --port 8080Open the list page in your browser:
http://localhost:8080/admin/product/listThe list page URL depends on the admin route prefix of your application. The Starter uses /admin.
TIP
The full walkthrough, including the product table, seeders, and grid features, is in the Rapid Application Development guide.
What the Generator Creates
unicorn:mvc-admin runs the smaller generators in sequence:
unicorn:modelcreates theApp\Entity\ProductORM entity and theApp\Repository\ProductRepositoryrepository.mig:createcreates a migration for the new table.seed:createcreates a seeder.unicorn:controllercreates theProductControllercontroller.unicorn:view-gridcreates the list view and its grid form.unicorn:view-editcreates the edit view and its edit form.unicorn:routeregisters the list and edit routes.
Each part can also be generated alone. Use --grid or --edit to limit unicorn:mvc-admin to one view:
php windwalker g unicorn:mvc-admin Admin/Product --gridRun php windwalker g to list every generator command.
Apply the Migration
The generator writes the migration but does not run it. Apply it with mig:go:
php windwalker mig:goWARNING
mig:go -f skips the confirmation prompt. Run it without -f on any database that holds data you need.
Re-generating Code
Generated files are not overwritten by default. The --force option replaces existing files:
php windwalker g unicorn:mvc-admin Admin/Product --forceWARNING
--force overwrites entity, controller, view, and route files that you may have edited. Commit your changes before using it.